From: Ian Holsman Date: Tue, 29 Jan 2002 21:08:37 +0000 (+0000) Subject: new directive 'ProxyPreserveHost' which allows the incoming host line to X-Git-Tag: 2.0.31~34 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c23a0b87320309b284a20f60c188abab8fef3cc3;p=apache new directive 'ProxyPreserveHost' which allows the incoming host line to be sent to the proxied server. Submitted by: g.russell@ieee.org (1.3 version) Reviewed by: Ian Holsman/Graham Legget/Chuck Murcko git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93089 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 0f26047225..25a6de18bf 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,9 @@ Changes with Apache 2.0.31-dev + + *) New Directive for mod_proxy: 'ProxyPreserveHost'. This passes + the incoming host header through to the proxied server + [Geoff ] + *) New Directive Option for ProxyPass. It now can block a location from being proxied [Jukka Pihl ] diff --git a/docs/manual/mod/mod_proxy.html b/docs/manual/mod/mod_proxy.html index 0fd3fb01a8..21c6a6b888 100644 --- a/docs/manual/mod/mod_proxy.html +++ b/docs/manual/mod/mod_proxy.html @@ -72,18 +72,19 @@ into a new module, mod_cache.

Directives

@@ -222,6 +223,44 @@ to the correct, fully qualified, server address. This is the preferred method since the user's bookmark files will then contain fully qualified hosts.


+

ProxyPreserveHost directive

+Syntax: ProxyPreserveHost on|off
+Default: ProxyPreserveHost Off
+Context: server config, virtual host
+Override: Not applicable
+Status: Base
+Module: mod_proxy
+Compatibility: ProxyPreserveHost is only available in +Apache 2.0.31 and later.

+ +When enabled, this option will pass the Host: line from the incoming request to +the proxied host, instead of the hostname specified in the proxypass line. +

+

This option should normally be turned 'off'.

+ +
+

ProxyRequests directive

maxfwd_set = 0; ps->error_override = 0; ps->error_override_set = 0; + ps->preserve_host_set =0; + ps->preserve_host =0; return ps; } @@ -515,6 +517,7 @@ static void * merge_proxy_config(apr_pool_t *p, void *basev, void *overridesv) ps->recv_buffer_size = (overrides->recv_buffer_size_set == 0) ? base->recv_buffer_size : overrides->recv_buffer_size; ps->maxfwd = (overrides->maxfwd_set == 0) ? base->maxfwd : overrides->maxfwd; ps->error_override = (overrides->error_override_set == 0) ? base->error_override : overrides->error_override; + ps->preserve_host = (overrides->preserve_host_set == 0) ? base->preserve_host : overrides->preserve_host; return ps; } @@ -780,6 +783,16 @@ static const char * psf->error_override_set = 1; return NULL; } +static const char * + set_preserve_host(cmd_parms *parms, void *dummy, int flag) +{ + proxy_server_conf *psf = + ap_get_module_config(parms->server->module_config, &proxy_module); + + psf->preserve_host = flag; + psf->preserve_host_set = 1; + return NULL; +} static const char * set_recv_buffer_size(cmd_parms *parms, void *dummy, const char *arg) @@ -953,6 +966,9 @@ static const command_rec proxy_cmds[] = "Configure Via: proxy header header to one of: on | off | block | full"), AP_INIT_FLAG("ProxyErrorOverride", set_proxy_error_override, NULL, RSRC_CONF, "use our error handling pages instead of the servers we are proxying"), + AP_INIT_FLAG("ProxyPreserveHost", set_preserve_host, NULL, RSRC_CONF, + "on if we shoud preserve host header while proxying"), + {NULL} }; diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 7ae7646c48..f81dfa4c61 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -187,6 +187,8 @@ typedef struct { */ int error_override; int error_override_set; + int preserve_host; + int preserve_host_set; } proxy_server_conf; diff --git a/modules/proxy/proxy_http.c b/modules/proxy/proxy_http.c index ebaf107db8..29887e0890 100644 --- a/modules/proxy/proxy_http.c +++ b/modules/proxy/proxy_http.c @@ -488,16 +488,32 @@ apr_status_t ap_proxy_http_request(apr_pool_t *p, request_rec *r, buf = apr_pstrcat(p, r->method, " ", url, " HTTP/1.1" CRLF, NULL); e = apr_bucket_pool_create(buf, strlen(buf), p); APR_BRIGADE_INSERT_TAIL(bb, e); - if (uri->port_str && uri->port != DEFAULT_HTTP_PORT) { - buf = apr_pstrcat(p, "Host: ", uri->hostname, ":", uri->port_str, CRLF, - NULL); - e = apr_bucket_pool_create(buf, strlen(buf), p); - APR_BRIGADE_INSERT_TAIL(bb, e); - } else { - buf = apr_pstrcat(p, "Host: ", uri->hostname, CRLF, NULL); - e = apr_bucket_pool_create(buf, strlen(buf), p); - APR_BRIGADE_INSERT_TAIL(bb, e); + if ( conf->preserve_host == 0 ) { + if (uri->port_str && uri->port != DEFAULT_HTTP_PORT) { + buf = apr_pstrcat(p, "Host: ", uri->hostname, ":", uri->port_str, CRLF, + NULL); + } else { + buf = apr_pstrcat(p, "Host: ", uri->hostname, CRLF, NULL); + } + } + else { + /* don't want to use r->hostname, as the incoming header might have a + * port attached + */ + const char* hostname = apr_table_get(r->headers_in,"Host"); + if (!hostname) { + hostname = r->server->server_hostname; + ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, r, + "proxy: no HTTP 0.9 request (with no host line) " + "on incoming request and preserve host set " + "forcing hostname to be %s for uri %s", + hostname, + r->uri ); + } + buf = apr_pstrcat(p, "Host: ", hostname, CRLF, NULL); } + e = apr_bucket_pool_create(buf, strlen(buf), p); + APR_BRIGADE_INSERT_TAIL(bb, e); /* handle Via */ if (conf->viaopt == via_block) {