goproxy
goproxy copied to clipboard
"curl host" and "curl host:80" produce different results
For a minimum goproxy example:
func main() {
proxy := goproxy.NewProxyHttpServer()
proxy.Verbose = true
log.Fatal(http.ListenAndServe(":8080", proxy))
}
curl http://www.baidu.com/ -k -v -x "http://127.0.0.1:8080"
returns 200;
curl http://www.baidu.com:80/ -k -v -x "http://127.0.0.1:8080"
returns 302.
(If we request without the proxy, the two commands will both produce the same 200 result.)
After some inspection I find out that, with the proxy, the first request from proxy to server is
GET / HTTP/1.1
Host: www.baidu.com
User-Agent: curl/7.65.3
Accept: */*
Accept-Encoding: gzip
and the second one is
GET / HTTP/1.1
Host: www.baidu.com:80
User-Agent: curl/7.65.3
Accept: */*
Accept-Encoding: gzip
Without the proxy, two requests from curl to server are the first one without port 80.
Should the proxy strip the protocol-default port or preserve it?
For the specifications, I skimmed rfc7230 which states "If the port subcomponent is empty or not given, TCP port 80 (the reserved port for WWW services) is the default.", but is still not sure if this behavior is correct / acceptable / incorrect.