]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Fold in the UseCanonicalPhysicalPort code, along with the
authorJim Jagielski <jim@apache.org>
Tue, 15 Nov 2005 19:39:15 +0000 (19:39 +0000)
committerJim Jagielski <jim@apache.org>
Tue, 15 Nov 2005 19:39:15 +0000 (19:39 +0000)
docs changes (just source currently)

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@344416 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/manual/mod/core.xml
docs/manual/server-wide.xml
include/ap_mmn.h
include/http_core.h
server/core.c

diff --git a/CHANGES b/CHANGES
index 63e2a522d43b7aade5cc0516260aa2f369e34667..a7ebcfb88181ec9d39a8dfc01a30feba2b8b4329 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,10 @@
                                                         -*- coding: utf-8 -*-
 Changes with Apache 2.1.10
 
+  *) Add in new UseCanonicalPhysicalPort directive, which controls
+     whether or not Apache will ever use the actual physical port
+     when constructing the canonical port number. [Jim Jagielski]
+
   *) mod_dav: Fix a null pointer dereference in an error code path during the
      handling of MKCOL.
      [Ruediger Pluem, Ghassan Misherghi <ghassanm ucdavis.edu>]
index 99372b62a37ab74409259904194d37e33c150cf1..d8f5c0de96cfb8c542fa2e0123e69d1fac0830fa 100644 (file)
@@ -2742,7 +2742,8 @@ itself</description>
     <code>Host:</code> header to match this virtual host.</p>
 
     <p>See the description of the
-    <directive module="core">UseCanonicalName</directive> directive for
+    <directive module="core">UseCanonicalName</directive> and
+    <directive module="core">UseCanonicalPhysicalPort</directive>directives for
     settings which determine whether self-referential URL's (e.g., by the
     <module>mod_dir</module> module) will refer to the
     specified port, or to the port number given in the client's request.
@@ -2754,6 +2755,7 @@ itself</description>
 <seealso><a href="../vhosts/">Apache virtual host
     documentation</a></seealso>
 <seealso><directive module="core">UseCanonicalName</directive></seealso>
+<seealso><directive module="core">UseCanonicalPhysicalPort</directive></seealso>
 <seealso><directive module="core">NameVirtualHost</directive></seealso>
 <seealso><directive module="core">ServerAlias</directive></seealso>
 </directivesynopsis>
@@ -3121,6 +3123,54 @@ port</description>
     then it should be just fine.</p>
     </note>
 </usage>
+<seealso><directive module="core">UseCanonicalPhysicalPort</directive></seealso>
+<seealso><directive module="core">ServerName</directive></seealso>
+<seealso><directive module="mpm_common">Listen</directive></seealso>
+</directivesynopsis>
+
+<directivesynopsis>
+<name>UseCanonicalPhysicalPort</name>
+<description>Configures how the server determines its own name and
+port</description>
+<syntax>UseCanonicalPhysicalPort On|Off</syntax>
+<default>UseCanonicalPhysicalPort Off</default>
+<contextlist><context>server config</context><context>virtual host</context>
+<context>directory</context></contextlist>
+
+<usage>
+    <p>In many situations Apache must construct a <em>self-referential</em>
+    URL -- that is, a URL that refers back to the same server. With
+    <code>UseCanonicalPhysicalPort On</code> Apache will, when
+    constructing the canonical port for the server to honor
+    the <directive module="core">UseCanonicalName</directive> directive,
+    provide the actual physical port number being used by this request
+    as a potential port. With <code>UseCanonicalPhysicalPort Off</code>
+    Apache will not ever use the actual physical port number, instead
+    relying on all configured information to construct a valid port number.</p>
+
+    <note><title>Note</title>
+    <p>The ordering of when the physical port is used is as follows:<br /><br />
+     <code>UseCanonicalName On</code>
+     <ul>
+      <li>Port provided in <code>Servername</code></li>
+      <li>Physical port</li>
+      <li>Default port</li>
+     </ul>
+     <code>UseCanonicalName Off | DNS</code>
+     <ul>
+      <li>Parsed port from <code>Host:</code> header</li>
+      <li>Physical port</li>
+      <li>Port provided in <code>Servername</code></li>
+      <li>Default port</li>
+     </ul>
+    </p>
+    
+    <p>With <code>UseCanonicalPhysicalPort Off</code>, the
+    physical ports are removed from the ordering.</p>
+    </note>
+
+</usage>
+<seealso><directive module="core">UseCanonicalName</directive></seealso>
 <seealso><directive module="core">ServerName</directive></seealso>
 <seealso><directive module="mpm_common">Listen</directive></seealso>
 </directivesynopsis>
index 57c31f48a543baa359f17292f5555e4d3d248d73..c78ca4052bedb25420f796d3a5a041bb88e7218e 100644 (file)
@@ -40,6 +40,7 @@ the basic operations of the server.</p>
         <directive module="core">ServerSignature</directive>
         <directive module="core">ServerTokens</directive>
         <directive module="core">UseCanonicalName</directive>
+        <directive module="core">UseCanonicalPhysicalPort</directive>
       </directivelist>
     </related>
 
@@ -50,8 +51,9 @@ the basic operations of the server.</p>
     <directive module="core">ServerTokens</directive> directive
     sets the value of the Server HTTP response header field.</p>
 
-    <p>The <directive module="core">ServerName</directive> and
-    <directive module="core">UseCanonicalName</directive>
+    <p>The <directive module="core">ServerName</directive>,
+    <directive module="core">UseCanonicalName</directive> and
+    <directive module="core">UseCanonicalPhysicalPort</directive>
     directives are used by the server to determine how to construct
     self-referential URLs. For example, when a client requests a
     directory, but does not include the trailing slash in the
index 443449e9e3fdbddaddaf19391988a73f310c0aa2..0fafcab7038b54e0a8185e744000f0296dbece62 100644 (file)
  * 20050708.0 (2.1.7-dev) Bump MODULE_MAGIC_COOKIE to "AP22"!
  * 20050708.1 (2.1.7-dev) add proxy request_status hook (minor)
  * 20051006.0 (2.1.8-dev) NET_TIME filter eliminated
+ * 20051115.0 (2.1.10-dev) Added use_canonical_phys_port to core_dir_config
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503232UL /* "AP22" */
 
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
-#define MODULE_MAGIC_NUMBER_MAJOR 20051006
+#define MODULE_MAGIC_NUMBER_MAJOR 20051115
 #endif
 #define MODULE_MAGIC_NUMBER_MINOR 0                     /* 0...n */
 
index 9060cb7a4e6ec6dba0527190750b0e66f88a909f..62f9e95e4093d327fb4c85edd8a28706c6855d43 100644 (file)
@@ -549,6 +549,12 @@ typedef struct {
     unsigned int enable_sendfile : 2;  /* files in this dir can be mmap'ed */
     unsigned int allow_encoded_slashes : 1; /* URLs may contain %2f w/o being
                                              * pitched indiscriminately */
+
+#define USE_CANONICAL_PHYS_PORT_OFF   (0)
+#define USE_CANONICAL_PHYS_PORT_ON    (1)
+#define USE_CANONICAL_PHYS_PORT_UNSET (2)
+    unsigned use_canonical_phys_port : 2;
+
 } core_dir_config;
 
 /* Per-server core configuration */
index 1a6bff63435a6fd444745a227ff888349feff636..8138d83f7abe7bf3078d5312602c90a6245bb657 100644 (file)
@@ -115,6 +115,7 @@ static void *create_core_dir_config(apr_pool_t *a, char *dir)
     conf->accept_path_info = 3;
 
     conf->use_canonical_name = USE_CANONICAL_NAME_UNSET;
+    conf->use_canonical_phys_port = USE_CANONICAL_PHYS_PORT_UNSET;
 
     conf->hostname_lookups = HOSTNAME_LOOKUP_UNSET;
     conf->satisfy = apr_palloc(a, sizeof(*conf->satisfy) * METHODS);
@@ -315,6 +316,10 @@ static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
         conf->use_canonical_name = new->use_canonical_name;
     }
 
+    if (new->use_canonical_phys_port != USE_CANONICAL_PHYS_PORT_UNSET) {
+        conf->use_canonical_phys_port = new->use_canonical_phys_port;
+    }
+
 #ifdef RLIMIT_CPU
     if (new->limit_cpu) {
         conf->limit_cpu = new->limit_cpu;
@@ -888,9 +893,7 @@ AP_DECLARE(const char *) ap_get_remote_logname(request_rec *r)
 
 /* There are two options regarding what the "name" of a server is.  The
  * "canonical" name as defined by ServerName and Port, or the "client's
- * name" as supplied by a possible Host: header or full URI.  We never
- * trust the port passed in the client's headers, we always use the
- * port of the actual socket.
+ * name" as supplied by a possible Host: header or full URI.
  *
  * The DNS option to UseCanonicalName causes this routine to do a
  * reverse lookup on the local IP address of the connection and use
@@ -903,30 +906,38 @@ AP_DECLARE(const char *) ap_get_server_name(request_rec *r)
 {
     conn_rec *conn = r->connection;
     core_dir_config *d;
+    const char *retval;
 
     d = (core_dir_config *)ap_get_module_config(r->per_dir_config,
                                                 &core_module);
 
-    if (d->use_canonical_name == USE_CANONICAL_NAME_ON) {
-        return r->server->server_hostname;
-    }
-
-    if (d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
-        if (conn->local_host == NULL) {
-            if (apr_getnameinfo(&conn->local_host,
+    switch (d->use_canonical_name) {
+        case USE_CANONICAL_NAME_ON:
+            retval = r->server->server_hostname;
+            break;
+        case USE_CANONICAL_NAME_DNS:
+            if (conn->local_host == NULL) {
+                if (apr_getnameinfo(&conn->local_host,
                                 conn->local_addr, 0) != APR_SUCCESS)
-                conn->local_host = apr_pstrdup(conn->pool,
+                    conn->local_host = apr_pstrdup(conn->pool,
                                                r->server->server_hostname);
-            else {
-                ap_str_tolower(conn->local_host);
+                else {
+                    ap_str_tolower(conn->local_host);
+                }
             }
-        }
-
-        return conn->local_host;
+            retval = conn->local_host;
+            break;
+        case USE_CANONICAL_NAME_OFF:
+        case USE_CANONICAL_NAME_UNSET:
+            retval = r->hostname ? r->hostname : r->server->server_hostname;
+            break;
+        default:
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                         "ap_get_server_name: Invalid UCN Option somehow");
+            retval = "localhost";
+            break;
     }
-
-    /* default */
-    return r->hostname ? r->hostname : r->server->server_hostname;
+    return retval;
 }
 
 /*
@@ -952,34 +963,44 @@ AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r)
     core_dir_config *d =
       (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
 
-    if (d->use_canonical_name == USE_CANONICAL_NAME_OFF
-        || d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
-
-        /* With UseCanonicalName off Apache will form self-referential
-         * URLs using the hostname and port supplied by the client if
-         * any are supplied (otherwise it will use the canonical name).
-         */
-        port = r->parsed_uri.port_str ? r->parsed_uri.port :
-               r->connection->local_addr->port ? r->connection->local_addr->port :
-               r->server->port ? r->server->port :
-               ap_default_port(r);
-    }
-    else { /* d->use_canonical_name == USE_CANONICAL_NAME_ON */
-
-        /* With UseCanonicalName on (and in all versions prior to 1.3)
-         * Apache will use the hostname and port specified in the
-         * ServerName directive to construct a canonical name for the
-         * server. (If no port was specified in the ServerName
-         * directive, Apache uses the port supplied by the client if
-         * any is supplied, and finally the default port for the protocol
-         * used.
-         */
-        port = r->server->port ? r->server->port :
-               r->connection->local_addr->port ? r->connection->local_addr->port :
-               ap_default_port(r);
+    switch (d->use_canonical_name) {
+        case USE_CANONICAL_NAME_OFF:
+        case USE_CANONICAL_NAME_DNS:
+        case USE_CANONICAL_NAME_UNSET:
+            if (d->use_canonical_phys_port == USE_CANONICAL_PHYS_PORT_ON)
+                port = r->parsed_uri.port_str ? r->parsed_uri.port :
+                       r->connection->local_addr->port ? r->connection->local_addr->port :
+                       r->server->port ? r->server->port :
+                       ap_default_port(r);
+            else /* USE_CANONICAL_PHYS_PORT_OFF or USE_CANONICAL_PHYS_PORT_UNSET */
+                port = r->parsed_uri.port_str ? r->parsed_uri.port :
+                       r->server->port ? r->server->port :
+                       ap_default_port(r);
+            break;
+        case USE_CANONICAL_NAME_ON:
+            /* With UseCanonicalName on (and in all versions prior to 1.3)
+             * Apache will use the hostname and port specified in the
+             * ServerName directive to construct a canonical name for the
+             * server. (If no port was specified in the ServerName
+             * directive, Apache uses the port supplied by the client if
+             * any is supplied, and finally the default port for the protocol
+             * used.
+             */
+            if (d->use_canonical_phys_port == USE_CANONICAL_PHYS_PORT_ON)
+                port = r->server->port ? r->server->port :
+                       r->connection->local_addr->port ? r->connection->local_addr->port :
+                       ap_default_port(r);
+            else /* USE_CANONICAL_PHYS_PORT_OFF or USE_CANONICAL_PHYS_PORT_UNSET */
+                port = r->server->port ? r->server->port :
+                       ap_default_port(r);
+            break;
+        default:
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                         "ap_get_server_port: Invalid UCN Option somehow");
+            port = ap_default_port(r);
+            break;
     }
 
-    /* default */
     return port;
 }
 
@@ -2484,6 +2505,29 @@ static const char *set_use_canonical_name(cmd_parms *cmd, void *d_,
     return NULL;
 }
 
+static const char *set_use_canonical_phys_port(cmd_parms *cmd, void *d_,
+                                          const char *arg)
+{
+    core_dir_config *d = d_;
+    const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
+
+    if (err != NULL) {
+        return err;
+    }
+
+    if (strcasecmp(arg, "on") == 0) {
+        d->use_canonical_phys_port = USE_CANONICAL_PHYS_PORT_ON;
+    }
+    else if (strcasecmp(arg, "off") == 0) {
+        d->use_canonical_phys_port = USE_CANONICAL_PHYS_PORT_OFF;
+    }
+    else {
+        return "parameter must be 'on' or 'off'";
+    }
+
+    return NULL;
+}
+
 
 static const char *include_config (cmd_parms *cmd, void *dummy,
                                    const char *name)
@@ -3259,6 +3303,9 @@ AP_INIT_FLAG("ContentDigest", set_content_md5, NULL, OR_OPTIONS,
 AP_INIT_TAKE1("UseCanonicalName", set_use_canonical_name, NULL,
   RSRC_CONF|ACCESS_CONF,
   "How to work out the ServerName : Port when constructing URLs"),
+AP_INIT_TAKE1("UseCanonicalPhysicalPort", set_use_canonical_phys_port, NULL,
+  RSRC_CONF|ACCESS_CONF,
+  "Whether to use the physical Port when constructing URLs"),
 /* TODO: RlimitFoo should all be part of mod_cgi, not in the core */
 /* TODO: ListenBacklog in MPM */
 AP_INIT_TAKE1("Include", include_config, NULL,