Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Add config setting which preserves host header #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion http_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
13 changes: 9 additions & 4 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ int maxSideBuffering = 1500;
int maxConnectionAge = 1260;
int maxConnectionRequests = 400;
int alwaysAddNoTransform = 0;
int useClientHostHeader = 0;

static HTTPServerPtr servers = 0;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions server.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ THE SOFTWARE.
*/

extern int serverExpireTime, dontCacheRedirects;
extern int useClientHostHeader;

typedef struct _HTTPServer {
char *name;
Expand Down