Skip to content

Commit

Permalink
set HTTP Host to request-target when using proxy
Browse files Browse the repository at this point in the history
To make the Host field carry the request-target it is enough to set
the Host information before changing the connection destination.

Many proxies rely on the Host field-value to route requests
in a violation of RFC7230 section 5.4.

https://tools.ietf.org/html/rfc7230#section-5.4

A request with the Host field set to the proxy hostname and port
in place of the request-target produces error responses and otherwise
confuses such misconfigured middleboxes.
  • Loading branch information
patch3proxyheaders915360 authored and arvidn committed Jul 1, 2019
1 parent 0fbd6bf commit 832857e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/http_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri
request << "Proxy-Authorization: Basic " << base64encode(
ps->username + ":" + ps->password) << "\r\n";

hostname = ps->hostname;
port = ps->port;

request << "Host: " << hostname;
if (port != default_port) request << ":" << port << "\r\n";
else request << "\r\n";

hostname = ps->hostname;
port = ps->port;
}
else
{
Expand Down

0 comments on commit 832857e

Please sign in to comment.