-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
Description
I wrote a simple reverse proxy using the built in http.ReverseProxy (thank you). Snooping with tcpdump on the backend, I noticed that a "Transfer-Encoding: chunked" header had been added to the GET request, even though there was no body and GET requests don't need a body in the first place. This may or may not be legal HTTP, but it certainly confuses some servers out there (notably www.google.com!) What steps will reproduce the problem? package main import ( "http" "flag" "log" ) var ( httpAddr = flag.String("http", ":12345", "HTTP service address") backendAddr = flag.String("backend", "www.google.com", "backend address") ) func director(req *http.Request) { req.URL.Scheme = "http" req.URL.Host = *backendAddr req.Host = *backendAddr } func main() { flag.Parse() proxy := &http.ReverseProxy{Director: director} err := http.ListenAndServe(*httpAddr, proxy) if err != nil { log.Fatal("ListenAndServe: ", err.String()) } } (some fields elided for anonymity) browser -> proxy -------- GET / HTTP/1.1 Host: XXX:12345 User-Agent: XXX Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 Cookie: XXX Cache-Control: max-age=0 Connection: keep-alive -------- proxy -> www.google.com -------- GET / HTTP/1.1 Host: www.google.com User-Agent: XXX Transfer-Encoding: chunked Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Cache-Control: max-age=0 Connection: keep-alive Cookie: XXX X-Forwarded-For: XXX 0 --------