diff --git a/config.sample b/config.sample index 4d9cdf92..c0c09164 100644 --- a/config.sample +++ b/config.sample @@ -159,3 +159,8 @@ # outgoing requests. # alwaysAddNoTransform = true + +# Uncomment this if you want to preserve the host header from the +# incoming host HTTP request. + +# useClientHostHeader = true diff --git a/http_parse.c b/http_parse.c index a5940ff3..38d5d4c1 100644 --- a/http_parse.c +++ b/http_parse.c @@ -1249,7 +1249,8 @@ httpParseHeaders(int client, AtomPtr url, cache_control.flags |= CACHE_COOKIE; if(hbuf) { - if(name != atomConnection && name != atomHost && + if(name != atomConnection && + (useClientHostHeader || name != atomHost) && name != atomAcceptRange && name != atomTE && name != atomProxyAuthenticate && name != atomKeepAlive && diff --git a/server.c b/server.c index f9f678ee..2aa2c0b4 100644 --- a/server.c +++ b/server.c @@ -40,6 +40,7 @@ int maxSideBuffering = 1500; int maxConnectionAge = 1260; int maxConnectionRequests = 400; int alwaysAddNoTransform = 0; +int useClientHostHeader = 0; static HTTPServerPtr servers = 0; @@ -95,6 +96,8 @@ preinitServer(void) "Maximum number of requests on a server-side connection."); CONFIG_VARIABLE(alwaysAddNoTransform, CONFIG_BOOLEAN, "If true, add a no-transform directive to all requests."); + CONFIG_VARIABLE_SETTABLE(useClientHostHeader, CONFIG_BOOLEAN, configIntSetter, + "Use client host header."); } static int @@ -1622,10 +1625,12 @@ httpWriteRequest(HTTPConnectionPtr connection, HTTPRequestPtr request, n = snnprintf(connection->reqbuf, n, bufsize, " HTTP/1.1"); - n = snnprintf(connection->reqbuf, n, bufsize, "\r\nHost: "); - n = snnprint_n(connection->reqbuf, n, bufsize, url + x, y - x); - if(port != 80) - n = snnprintf(connection->reqbuf, n, bufsize, ":%d", port); + if(!useClientHostHeader) { + n = snnprintf(connection->reqbuf, n, bufsize, "\r\nHost: "); + n = snnprint_n(connection->reqbuf, n, bufsize, url + x, y - x); + if(port != 80) + n = snnprintf(connection->reqbuf, n, bufsize, ":%d", port); + } if(connection->server->isProxy && parentAuthCredentials) { n = buildServerAuthHeaders(connection->reqbuf, n, bufsize, diff --git a/server.h b/server.h index c2cbb409..824ec90a 100644 --- a/server.h +++ b/server.h @@ -21,6 +21,7 @@ THE SOFTWARE. */ extern int serverExpireTime, dontCacheRedirects; +extern int useClientHostHeader; typedef struct _HTTPServer { char *name;