]> granicus.if.org Git - apache/commitdiff
Fixed previous patch to reflect what Apache-1.3 did regarding self-
authorMartin Kraemer <martin@apache.org>
Thu, 8 Nov 2001 14:29:37 +0000 (14:29 +0000)
committerMartin Kraemer <martin@apache.org>
Thu, 8 Nov 2001 14:29:37 +0000 (14:29 +0000)
referential uri's, and updated the manual accordingly.
XXX There is a kludge here: XXX the port number from the client's Host:
header used to be tossed, and there is no clean mechanism to pass it
(in the request_rec) to other consumers. As the unparsed_uri structure
(which could avoid repeated parsing of URI, Host, Port etc) seems to be
mostly unused currently, I used that to pass the port.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@91798 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/manual/mod/core.html
server/core.c
server/vhost.c

diff --git a/CHANGES b/CHANGES
index c40c621198d252be9f3fc2ff70b673f1b741d446..dfbb74e7e0404e71f7bb41af085bd3332fca730a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -5,7 +5,10 @@ Changes with Apache 2.0.28-dev
      run-time deduction of the correct server port (depending on
      SSL/plain, and depending also on the current setting of
      UseCanonicalName). This change makes redirections
-     work, even with https:// connections. [Martin Kraemer]
+     work, even with https:// connections. As in Apache-1.3, the
+     connection's actual port number is never used, only the ServerName
+     setting or the client's Host: setting. Documentation updated
+     to reflect the change. [Martin Kraemer]
 
   *) Add a '%{note-name}e' argument to mod-headers, which works in
      the same way as mod_log_confg.  [Ian Holsman]
index d49cf972576a389ade4db910f18d3e3eed2c5c81..2b8647946d5487abc2e27f6380561535f0b96e31 100644 (file)
     section specifies what hostname must appear in the request's
     <code>Host:</code> header to match this virtual host.</p>
 
-    <p>This directive now takes allows a port to be added to the
+    <p>This directive now allows a port to be added to the
     server name.  This allows an admin to assign the canonical
     port at the same time that the canonical name is assigned.
-    The Port directive, which used to perform this role, has also
-    been removed, easing configuration for all users. 
+    The Port directive in Apache-1.3, which used to perform this role, has also
+    been removed, easing configuration for all users.</p>
+
+    <p>If the port has been specified, then automatic redirections
+    (e.g., by the <a href="mod_dir.html">mod_dir</a> module) will
+    <em>always</em> use the given port, no matter what the actual
+    request's port number was. If no port number was specified, however,
+    the setting of <a href="#usecanonicalname">UseCanonicalName</a>
+    decides whether the default port (80 for http://, 443 for https://),
+    or the actual port the request came in on, will be used in redirections.
+    </p>
 
     <p><strong>See Also</strong>:<br />
      <a href="../dns-caveats.html">DNS Issues</a><br />
     <p>In many situations Apache has to construct a
     <em>self-referential</em> URL. That is, a URL which refers back
     to the same server. With <code>UseCanonicalName on</code> (and
-    in all versions prior to 1.3) Apache will use the <a
-    href="#servername">ServerName</a> and <a 
-    href="mpm_common.html#listen">Listen</a>
-    directives to construct a canonical name for the server. This
+    in all versions prior to 1.3) Apache will use the hostname and
+    port specified in the <a href="#servername">ServerName</a>
+    directive to construct a canonical name for the server.
+    (If no port was specified in the <a href="#servername">ServerName</a>
+    directive, Apache implies port 80 for http:// and port 443 for https://)
+    This
     name is used in all self-referential URLs, and for the values
     of <code>SERVER_NAME</code> and <code>SERVER_PORT</code> in
     CGIs.</p>
index 175c0ec1ce3961ed0e5ee862d04cc6c7903c9ad8..aec919bce08d5468a532bac0179ffa8fd5e0cdfd 100644 (file)
@@ -752,17 +752,29 @@ 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);
     
-    port = r->server->port ? r->server->port : ap_default_port(r);
-
     if (d->use_canonical_name == USE_CANONICAL_NAME_OFF
        || d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
-        if (r->connection && r->connection->client_socket) {
-            apr_sockaddr_t *localsa;
 
-            apr_socket_addr_get(&localsa, APR_LOCAL, r->connection->client_socket);
-            apr_sockaddr_port_get(&port, localsa);
-        }
+        /* 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 ? r->parsed_uri.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 implies port 80 for http:// and
+        * port 443 for https://)
+        */
+        port = r->server->port ? r->server->port : ap_default_port(r);
     }
+
     /* default */
     return port;
 }
index e6af2cd981d21ae74d1313df2afba940cc1d6969..cf3c2a27ccf04a8cf4edb13869d5df9458b5dd8b 100644 (file)
@@ -754,6 +754,15 @@ static void fix_hostname(request_rec *r)
          */
         host = apr_psprintf(r->pool, "%d", (int)port);
     }
+    else if (port) {
+        /* Don't throw the Host: header's port number away:
+          save it in parsed_uri -- ap_get_server_port() needs it! */
+        /* @@@ XXX there should be a better way to pass the port.
+        *         Like r->hostname, there should be a r->portno
+        */
+        r->parsed_uri.port = port;
+       r->parsed_uri.port_str = apr_psprintf(r->pool, "%d", (int)port);
+    }
 
     /* if the hostname is an IPv6 numeric address string, it was validated 
      * already; otherwise, further validation is needed