Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
1.7.4 (problem exists on master branch as well)
What operating system and processor architecture are you using (go env
)?
linux-amd64
What did you do?
Sample code here: https://play.golang.org/p/dpLc5rnHJZ
We have created a proxy server using the net/http package. If a HTTP client using the proxy server issues a CONNECT
request without a Host:
header, the golang HTTP server implementation will close the connection with 400 Bad Request: missing required Host header
error.
CONNECT api.surfeasy.com:443 HTTP/1.1
...
as opposed to:
CONNECT api.surfeasy.com:443 HTTP/1.1
Host: api.surfeasy.com:443
...
Now this could be a contentious issue as the HTTP 1.1 spec (see https://tools.ietf.org/html/rfc7230#section-5.4) specifies that a Host header is mandatory, but we see some VERY popular devices (i.e.: iOS devices) implement proxy clients that do not send the Host:
header when configured to use proxies (and as a result issue CONNECT
requests). This could be an artifact of interop with older HTTP 1.0 proxies.
It appears that the HTTP request code in src/net/http/request.go
will synthesize a Host attribute based on the CONNECT
parameters (authority-form) and ignores any Host:
header, so relaxing the Host header restriction would allow for better compatibility. As it stands now, any HTTP server implementing some form of CONNECT handler might not work with a large range of devices.
What did you expect to see?
Client CONNECT
request completes as expected and leaves connection open for further requests.
What did you see instead?
net/http Server implementation returns a 400 Bad Request: missing required Host header
and closes the connection.