> This is already implemented in 2.0 as ProxyPreserveHost, you may
> want to backport it to 1.3
>
> http://httpd.apache.org/docs-2.0/mod/mod_proxy.html#proxypreservehost
Ah. I have fixed up my patch to have the same name and few minor
tweaks to the patch to make it smaller. Can someone with CVS access
look the patch over and put it in?
Matt
--
Matt Kern
http://www.undue.org/
diff -ur apache.orig/htdocs/manual/mod/mod_proxy.html
apache_1.3.24/htdocs/manual/mod/mod_proxy.html
--- apache.orig/htdocs/manual/mod/mod_proxy.html Thu Mar 21 17:28:49 2002
+++ apache_1.3.24/htdocs/manual/mod/mod_proxy.html Fri May 31 18:57:58 2002
@@ -61,6 +61,8 @@
<li><a href="#proxypassreverse">ProxyPassReverse</a></li>
+ <li><a href="#proxypreservehost">ProxyPreserveHost</a></li>
+
<li><a href="#proxyblock">ProxyBlock</a></li>
<li><a href="#allowconnect">AllowCONNECT</a></li>
@@ -453,6 +455,31 @@
href="mod_rewrite.html#RewriteRule"><tt>mod_rewrite</tt></a>
because its doesn't depend on a corresponding
<samp>ProxyPass</samp> directive.</p>
+ <hr />
+
+ <h2><a id="proxypreservehost"
+ name="proxypreservehost">ProxyPreserveHost</a> directive</h2>
+ <a href="directive-dict.html#Syntax"
+ rel="Help"><strong>Syntax:</strong></a> ProxyPreserveHost
+ on|off<br />
+ <a href="directive-dict.html#Default"
+ rel="Help"><strong>Default:</strong></a> <code>ProxyPreserveHost Off</code><br />
+ <a href="directive-dict.html#Context"
+ rel="Help"><strong>Context:</strong></a> server config, virtual
+ host<br />
+ <a href="directive-dict.html#Override"
+ rel="Help"><strong>Override:</strong></a> <em>Not
+ applicable</em><br />
+ <a href="directive-dict.html#Status"
+ rel="Help"><strong>Status:</strong></a> Base<br />
+ <a href="directive-dict.html#Module"
+ rel="Help"><strong>Module:</strong></a> mod_proxy<br />
+ <a href="directive-dict.html#Compatibility"
+ rel="Help"><strong>Compatibility:</strong></a> ProxyPassReverse
+ is only available in Apache 1.3.25 and later.
+
+ <p>This directive tells Apache to preserve the <tt>Host</tt>
+ header from incoming requests on outgoing proxy requests.</p>
<hr />
<h2><a id="allowconnect" name="allowconnect">AllowCONNECT</a>
diff -ur apache.orig/src/modules/proxy/mod_proxy.c
apache_1.3.24/src/modules/proxy/mod_proxy.c
--- apache.orig/src/modules/proxy/mod_proxy.c Fri May 31 18:56:10 2002
+++ apache_1.3.24/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
--- apache.orig/src/modules/proxy/mod_proxy.h Fri May 31 18:56:10 2002
+++ apache_1.3.24/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
--- apache.orig/src/modules/proxy/proxy_http.c Fri May 31 18:56:10 2002
+++ apache_1.3.24/src/modules/proxy/proxy_http.c Fri May 31 18:57:58 2002
@@ -311,11 +311,14 @@
ap_hard_timeout("proxy send", r);
ap_bvputs(f, r->method, " ", proxyhost ? url : urlptr, " HTTP/1.1" CRLF,
NULL);
- /* 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);
+ }
if (conf->viaopt == via_block) {
/* Block all outgoing Via: headers */
@@ -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);
}