From 2e7d4a54b759eb9ad73af7adb0f08479d085d687 Mon Sep 17 00:00:00 2001 From: Daniel Stirnimann Date: Tue, 17 Jun 2014 14:01:25 +0200 Subject: [PATCH 1/4] Add config setting which preserves host header --- http_parse.c | 3 ++- server.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/http_parse.c b/http_parse.c index a5940ff3..35bd0531 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 && + ( useClienHostHeader || name != atomHost ) && name != atomAcceptRange && name != atomTE && name != atomProxyAuthenticate && name != atomKeepAlive && diff --git a/server.c b/server.c index f9f678ee..fdf6cecc 100644 --- a/server.c +++ b/server.c @@ -40,6 +40,7 @@ int maxSideBuffering = 1500; int maxConnectionAge = 1260; int maxConnectionRequests = 400; int alwaysAddNoTransform = 0; +int useClienHostHeader = 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(useClienHostHeader, 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(!useClienHostHeader) { + 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, From 92e956330beccd097168abac8cf883ac8e34f146 Mon Sep 17 00:00:00 2001 From: Daniel Stirnimann Date: Wed, 18 Jun 2014 15:58:33 +0200 Subject: [PATCH 2/4] Fix naming of variable useClientHostHeader Fix space between brackets --- http_parse.c | 2 +- server.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/http_parse.c b/http_parse.c index 35bd0531..38d5d4c1 100644 --- a/http_parse.c +++ b/http_parse.c @@ -1250,7 +1250,7 @@ httpParseHeaders(int client, AtomPtr url, if(hbuf) { if(name != atomConnection && - ( useClienHostHeader || name != atomHost ) && + (useClientHostHeader || name != atomHost) && name != atomAcceptRange && name != atomTE && name != atomProxyAuthenticate && name != atomKeepAlive && diff --git a/server.c b/server.c index fdf6cecc..2aa2c0b4 100644 --- a/server.c +++ b/server.c @@ -40,7 +40,7 @@ int maxSideBuffering = 1500; int maxConnectionAge = 1260; int maxConnectionRequests = 400; int alwaysAddNoTransform = 0; -int useClienHostHeader = 0; +int useClientHostHeader = 0; static HTTPServerPtr servers = 0; @@ -96,7 +96,7 @@ 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(useClienHostHeader, CONFIG_BOOLEAN, configIntSetter, + CONFIG_VARIABLE_SETTABLE(useClientHostHeader, CONFIG_BOOLEAN, configIntSetter, "Use client host header."); } @@ -1625,7 +1625,7 @@ httpWriteRequest(HTTPConnectionPtr connection, HTTPRequestPtr request, n = snnprintf(connection->reqbuf, n, bufsize, " HTTP/1.1"); - if(!useClienHostHeader) { + if(!useClientHostHeader) { n = snnprintf(connection->reqbuf, n, bufsize, "\r\nHost: "); n = snnprint_n(connection->reqbuf, n, bufsize, url + x, y - x); if(port != 80) From c063d8acbd45fe2831734ce5b5de8cc585daf1ac Mon Sep 17 00:00:00 2001 From: Daniel Stirnimann Date: Wed, 18 Jun 2014 16:00:11 +0200 Subject: [PATCH 3/4] Add useClientHostHeader to config.sample --- config.sample | 5 +++++ 1 file changed, 5 insertions(+) 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 From f9fbfbce78951927a3d4f0a9032fb12cb9663316 Mon Sep 17 00:00:00 2001 From: Daniel Stirnimann Date: Mon, 23 Jun 2014 13:31:02 +0200 Subject: [PATCH 4/4] fix variable declaration of useClientHostHeader --- server.h | 1 + 1 file changed, 1 insertion(+) 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;