We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version
go version devel +babdbfb Tue May 3 12:35:09 2016 +0000 darwin/amd64
What operating system and processor architecture are you using (go env)?
go env
darwin/amd64, OS X 10.11.4
What did you do?
User-Agent
curl -v -H "User-Agent:" http://localhost:8080/
What did you expect to see?
The program reports that User-Agent header is empty: User-Agent is ""
User-Agent is ""
What did you see instead?
The program reports that User-Agent is set to default value: User-Agent is "Go-http-client/1.1"
User-Agent is "Go-http-client/1.1"
The text was updated successfully, but these errors were encountered:
Possible fix is trivial:
diff --git i/src/net/http/httputil/reverseproxy.go w/src/net/http/httputil/reverseproxy.go index 44d15ff..8c471a9 100644 --- i/src/net/http/httputil/reverseproxy.go +++ w/src/net/http/httputil/reverseproxy.go @@ -90,6 +90,11 @@ func NewSingleHostReverseProxy(target *url.URL) *ReverseProxy { } else { req.URL.RawQuery = targetQuery + "&" + req.URL.RawQuery } + if _, ok := req.Header["User-Agent"]; !ok { + // explicitly disable User-Agent so it's not set to + // default value + req.Header.Set("User-Agent", "") + } } return &ReverseProxy{Director: director} } diff --git i/src/net/http/httputil/reverseproxy_test.go w/src/net/http/httputil/reverseproxy_test.go index e9c0658..1065561 100644 --- i/src/net/http/httputil/reverseproxy_test.go +++ w/src/net/http/httputil/reverseproxy_test.go @@ -41,6 +41,9 @@ func TestReverseProxy(t *testing.T) { if len(r.TransferEncoding) > 0 { t.Errorf("backend got unexpected TransferEncoding: %v", r.TransferEncoding) } + if c := r.Header.Get("User-Agent"); c != "" { + t.Errorf("handler got User-Agent header value %q", c) + } if r.Header.Get("X-Forwarded-For") == "" { t.Errorf("didn't get X-Forwarded-For header") } @@ -80,6 +83,7 @@ func TestReverseProxy(t *testing.T) { getReq, _ := http.NewRequest("GET", frontend.URL, nil) getReq.Host = "some-name" + getReq.Header.Set("User-Agent", "") getReq.Header.Set("Connection", "close") getReq.Header.Set("Proxy-Connection", "should be deleted") getReq.Header.Set("Upgrade", "foo")
Please let me know if this change makes sense, I can proceed with CL then.
Sorry, something went wrong.
@artyom, sure, send a CL. Be sure to also add a test that the original User-Agent from a user is preserved.
Sure, will do this later this week, likely over the weekend. Please feel free to assing this to me.
CL https://golang.org/cl/23089 mentions this issue.
6a6c1d9
No branches or pull requests
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
User-Agent
header unset:curl -v -H "User-Agent:" http://localhost:8080/
What did you expect to see?
The program reports that User-Agent header is empty:
User-Agent is ""
What did you see instead?
The program reports that User-Agent is set to default value:
User-Agent is "Go-http-client/1.1"
The text was updated successfully, but these errors were encountered: