]> granicus.if.org Git - apache/commitdiff
new directive 'ProxyPreserveHost' which allows the incoming host line to
authorIan Holsman <ianh@apache.org>
Tue, 29 Jan 2002 21:08:37 +0000 (21:08 +0000)
committerIan Holsman <ianh@apache.org>
Tue, 29 Jan 2002 21:08:37 +0000 (21:08 +0000)
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

CHANGES
docs/manual/mod/mod_proxy.html
modules/proxy/mod_proxy.c
modules/proxy/mod_proxy.h
modules/proxy/proxy_http.c

diff --git a/CHANGES b/CHANGES
index 0f2604722536290cef95014b997d4810cd24409e..25a6de18bf24eb09dce38bb4208066abe2a439c0 100644 (file)
--- 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 <g.russell@ieee.org>]
+
   *) New Directive Option for ProxyPass. It now can block a location
      from being proxied [Jukka Pihl <jukka.pihl@entirem.com>]
 
index 0fd3fb01a815bf4003cf744ffe98352d83727184..21c6a6b8884758439d822643e3ce30cd27bd9c8c 100644 (file)
@@ -72,18 +72,19 @@ into a new module, mod_cache.
 
 <H2>Directives</H2>
 <UL>
-<LI><A HREF="#proxyrequests">ProxyRequests</A>
-<LI><A HREF="#proxyremote">ProxyRemote</A>
-<LI><A HREF="#proxypass">ProxyPass</A>
-<LI><A HREF="#proxypassreverse">ProxyPassReverse</A>
-<LI><A HREF="#proxyblock">ProxyBlock</A>
 <LI><A HREF="#allowconnect">AllowCONNECT</A>
-<LI><A HREF="#proxyreceivebuffersize">ProxyReceiveBufferSize</A>
-<LI><A HREF="#proxymaxforwards">ProxyMaxForwards</A>
 <LI><A HREF="#noproxy">NoProxy</A>
+<LI><A HREF="#proxyblock">ProxyBlock</A>
 <LI><A HREF="#proxydomain">ProxyDomain</A>
-<LI><A HREF="#proxyvia">ProxyVia</A>
 <LI><A HREF="#proxyerroroverride">ProxyErrorOverride</A>
+<LI><A HREF="#proxymaxforwards">ProxyMaxForwards</A>
+<LI><A HREF="#proxypass">ProxyPass</A>
+<LI><A HREF="#proxypassreverse">ProxyPassReverse</A>
+<LI><A HREF="#proxypreservehost">ProxyPreserveHost</A>
+<LI><A HREF="#proxyreceivebuffersize">ProxyReceiveBufferSize</A>
+<LI><A HREF="#proxyremote">ProxyRemote</A>
+<LI><A HREF="#proxyrequests">ProxyRequests</A>
+<LI><A HREF="#proxyvia">ProxyVia</A>
 
 </UL>
 
@@ -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.</P>
 
 <HR>
+<H2><A NAME="proxyrequests">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> ProxyPreserveHost is only available in
+Apache 2.0.31 and later.<P>
+
+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.
+</P>
+<P>This option should normally be turned 'off'.</P>
+
+<HR>
+
 
 <H2><A NAME="proxyrequests">ProxyRequests</A> directive</H2>
 <A
index 9bb07a859af5370630079a2cef4b406ece11388f..0e3acf3261c91ceb9ae42b350a458434dce43ce6 100644 (file)
@@ -492,6 +492,8 @@ static void * create_proxy_config(apr_pool_t *p, server_rec *s)
     ps->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}
 };
 
index 7ae7646c48c9068ea08f43b0dd3b476ad7ca9340..f81dfa4c61b128eee5591fbad08f48944efc5ce8 100644 (file)
@@ -187,6 +187,8 @@ typedef struct {
      */
     int error_override;
     int error_override_set;
+    int preserve_host;
+    int preserve_host_set;
 
 } proxy_server_conf;
 
index ebaf107db8337e04bcc31a971e33d39e84bd69c0..29887e08906087a28c71076f9e35af7f9d42273d 100644 (file)
@@ -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) {