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
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]
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>
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;
}
*/
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