diff -ur apache.orig/htdocs/manual/mod/mod_proxy.html apache_1.3.24/htdocs/manual/mod/mod_proxy.html --- htdocs/manual/mod/mod_proxy.html Thu Mar 21 17:28:49 2002 +++ htdocs/manual/mod/mod_proxy.html Fri May 31 18:57:58 2002 @@ -61,6 +61,8 @@
  • ProxyPassReverse
  • +
  • ProxyPreserveHost
  • +
  • ProxyBlock
  • AllowCONNECT
  • @@ -453,6 +455,31 @@ href="mod_rewrite.html#RewriteRule">mod_rewrite because its doesn't depend on a corresponding ProxyPass directive.

    +
    + +

    ProxyPreserveHost directive

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

    This directive tells Apache to preserve the Host + header from incoming requests on outgoing proxy requests.


    AllowCONNECT diff -ur apache.orig/src/modules/proxy/mod_proxy.c apache_1.3.24/src/modules/proxy/mod_proxy.c --- src/modules/proxy/mod_proxy.c Fri May 31 18:56:10 2002 +++ src/modules/proxy/mod_proxy.c Fri May 31 18:57:58 2002 @@ -436,6 +436,8 @@ ps->viaopt_set = 0; /* 0 means default */ ps->req = 0; ps->req_set = 0; + ps->phh = 0; + ps->phh_set = 0; ps->recv_buffer_size = 0; /* this default was left unset for some * reason */ ps->recv_buffer_size_set = 0; @@ -483,6 +485,7 @@ ps->domain = (overrides->domain == NULL) ? base->domain : overrides->domain; ps->viaopt = (overrides->viaopt_set == 0) ? base->viaopt : overrides->viaopt; ps->req = (overrides->req_set == 0) ? base->req : overrides->req; + ps->phh = (overrides->phh_set == 0) ? base->phh : overrides->phh; ps->recv_buffer_size = (overrides->recv_buffer_size_set == 0) ? base->recv_buffer_size : overrides->recv_buffer_size; ps->io_buffer_size = (overrides->io_buffer_size_set == 0) ? base->io_buffer_size : overrides->io_buffer_size; @@ -703,6 +706,19 @@ static const char * + set_proxy_preserve_host(cmd_parms *parms, void *dummy, int flag) +{ + proxy_server_conf *psf = + ap_get_module_config(parms->server->module_config, &proxy_module); + + psf->phh = flag; + psf->phh_set = 1; + + return NULL; +} + + +static const char * set_cache_size(cmd_parms *parms, char *struct_ptr, char *arg) { proxy_server_conf *psf = @@ -936,6 +952,8 @@ "a virtual path and a URL"}, {"ProxyPassReverse", add_pass_reverse, NULL, RSRC_CONF, TAKE2, "a virtual path and a URL for reverse proxy behaviour"}, + {"ProxyPreserveHost", set_proxy_preserve_host, NULL, RSRC_CONF, FLAG, + "on if the original Host: header should be preserved"}, {"ProxyBlock", set_proxy_exclude, NULL, RSRC_CONF, ITERATE, "A list of names, hosts or domains to which the proxy will not connect"}, {"ProxyReceiveBufferSize", set_recv_buffer_size, NULL, RSRC_CONF, TAKE1, diff -ur apache.orig/src/modules/proxy/mod_proxy.h apache_1.3.24/src/modules/proxy/mod_proxy.h --- src/modules/proxy/mod_proxy.h Fri May 31 18:56:10 2002 +++ src/modules/proxy/mod_proxy.h Fri May 31 18:57:58 2002 @@ -192,6 +192,8 @@ char *domain; /* domain name to use in absence of a domain name in the request */ int req; /* true if proxy requests are enabled */ char req_set; + int phh; /* true if we want to preserve the host header */ + char phh_set; enum { via_off, via_on, diff -ur apache.orig/src/modules/proxy/proxy_http.c apache_1.3.24/src/modules/proxy/proxy_http.c --- src/modules/proxy/proxy_http.c Fri May 31 18:56:10 2002 +++ src/modules/proxy/proxy_http.c Fri May 31 18:57:58 2002 @@ -312,7 +312,7 @@ AP_HOOK_SIG6(int,ptr,ptr,ptr,int,ptr), AP_HOOK_DECLINE(DECLINED), &rc, r, f, desthost, destport, destportstr); - if (rc == DECLINED) { + if (rc == DECLINED && !conf->phh) { if (destportstr != NULL && destport != DEFAULT_HTTP_PORT) ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF, NULL); else @@ -320,11 +320,14 @@ } } #else /* EAPI */ - /* Send Host: now, adding it to req_hdrs wouldn't be much better */ - if (destportstr != NULL && destport != DEFAULT_HTTP_PORT) - ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF, NULL); - else - ap_bvputs(f, "Host: ", desthost, CRLF, NULL); + /* Don't send Host: if we are preserving it */ + if (!conf->phh) { + /* Send Host: now, adding it to req_hdrs wouldn't be much better */ + if (destportstr != NULL && destport != DEFAULT_HTTP_PORT) + ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF, NULL); + else + ap_bvputs(f, "Host: ", desthost, CRLF, NULL); + } #endif /* EAPI */ if (conf->viaopt == via_block) { @@ -363,7 +366,6 @@ * Clear out hop-by-hop request headers not to send: RFC2616 13.5.1 * says we should strip these headers: */ - || !strcasecmp(reqhdrs_elts[i].key, "Host") /* Already sent */ || !strcasecmp(reqhdrs_elts[i].key, "Keep-Alive") || !strcasecmp(reqhdrs_elts[i].key, "TE") || !strcasecmp(reqhdrs_elts[i].key, "Trailer") @@ -380,6 +382,9 @@ * was authenticated or not. */ || !strcasecmp(reqhdrs_elts[i].key, "Proxy-Authorization")) + continue; + /* Don't drop Host if we are preserving it */ + if (!conf->phh && !strcasecmp(reqhdrs_elts[i].key, "Host")) continue; ap_bvputs(f, reqhdrs_elts[i].key, ": ", reqhdrs_elts[i].val, CRLF, NULL); }