From: Martin Kraemer
Date: Thu, 8 Nov 2001 14:29:37 +0000 (+0000)
Subject: Fixed previous patch to reflect what Apache-1.3 did regarding self-
X-Git-Tag: 2.0.28~9
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ac0d5e631744b7f599e327d3028277ce2845a6d0;p=apache
Fixed previous patch to reflect what Apache-1.3 did regarding self-
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
---
diff --git a/CHANGES b/CHANGES
index c40c621198..dfbb74e7e0 100644
--- 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]
diff --git a/docs/manual/mod/core.html b/docs/manual/mod/core.html
index d49cf97257..2b8647946d 100644
--- a/docs/manual/mod/core.html
+++ b/docs/manual/mod/core.html
@@ -2232,11 +2232,20 @@
section specifies what hostname must appear in the request's
Host:
header to match this virtual host.
- This directive now takes allows a port to be added to the
+
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.
+
+ If the port has been specified, then automatic redirections
+ (e.g., by the mod_dir module) will
+ always use the given port, no matter what the actual
+ request's port number was. If no port number was specified, however,
+ the setting of UseCanonicalName
+ 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.
+
See Also:
DNS Issues
@@ -2547,10 +2556,12 @@
In many situations Apache has to construct a
self-referential URL. That is, a URL which refers back
to the same server. With UseCanonicalName on
(and
- in all versions prior to 1.3) Apache will use the ServerName and Listen
- 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 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://)
+ This
name is used in all self-referential URLs, and for the values
of SERVER_NAME
and SERVER_PORT
in
CGIs.
diff --git a/server/core.c b/server/core.c
index 175c0ec1ce..aec919bce0 100644
--- a/server/core.c
+++ b/server/core.c
@@ -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;
}
diff --git a/server/vhost.c b/server/vhost.c
index e6af2cd981..cf3c2a27cc 100644
--- a/server/vhost.c
+++ b/server/vhost.c
@@ -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