From: Jeff Trawick Date: Tue, 22 Apr 2003 14:51:42 +0000 (+0000) Subject: Fix ap_construct_url() so that it surrounds IPv6 literal address X-Git-Tag: pre_ajp_proxy~1804 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=39402b244a0bf59ad382c9ce74ca382e17fa4c46;p=thirdparty%2Fapache%2Fhttpd.git Fix ap_construct_url() so that it surrounds IPv6 literal address strings with []. This fixes certain types of redirection. PR: 19207 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@99517 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 38e182aabb6..ea6f5263ca4 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,10 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) Fix ap_construct_url() so that it surrounds IPv6 literal address + strings with []. This fixes certain types of redirection. + PR 19207. [Jeff Trawick] + *) mod_log_config: Add the ability to log the id of the thread processing the request via new %P formats. [Jeff Trawick] diff --git a/server/core.c b/server/core.c index f2635fb2221..328933ddab6 100644 --- a/server/core.c +++ b/server/core.c @@ -885,6 +885,23 @@ AP_DECLARE(const char *) ap_get_server_name(request_rec *r) return r->server->server_hostname; } +/* + * Get the current server name from the request for the purposes + * of using in a URL. If the server name is an IPv6 literal + * address, it will be returned in URL format (e.g., "[fe80::1]"). + */ +static const char *get_server_name_for_url(request_rec *r) +{ + const char *plain_server_name = ap_get_server_name(r); + +#ifdef APR_HAVE_IPV6 + if (ap_strchr_c(plain_server_name, ':')) { /* IPv6 literal? */ + return apr_psprintf(r->pool, "[%s]", plain_server_name); + } +#endif + return plain_server_name; +} + AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r) { apr_port_t port; @@ -925,7 +942,7 @@ AP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri, request_rec *r) { unsigned port = ap_get_server_port(r); - const char *host = ap_get_server_name(r); + const char *host = get_server_name_for_url(r); if (ap_is_default_port(port, r)) { return apr_pstrcat(p, ap_http_method(r), "://", host, uri, NULL);