httpproxyrequesthttp-proxy

Should the Host header always required in HTTP Proxy CONNECT requests?


Based on this example, an HTTP CONNECT request can have a Host and an Proxy-Authorization header.

CONNECT server.example.com:80 HTTP/1.1\r\n
Host: server.example.com:80\r\n
Proxy-Authorization: basic aGVsbG86d29ybGQ=\r\n\r\n

The Proxy-Authorization header is optional.

Is the Host header also optional, and should we (as a proxy server) accept a request as follows without the additional lines of headers?

CONNECT server.example.com:443 HTTP/1.1\r\n\r\n

Solution

  • RFC 2616 states in Section 14.23:

    A client MUST include a Host header field in all HTTP/1.1 request messages .
    

    A CONNECT request is an HTTP request. Therefore, as long as the request line specifies HTTP/1.1, the Host header is mandatory even in CONNECT requests. If you want to strictly comply with the standard, your proxy server should not accept HTTP/1.1 requests without this header.