Skip to content
New issue

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

net/http/httputil: WebSocket requests do not use ModifyResponse in ReverseProxy #29627

Closed
blixt opened this issue Jan 9, 2019 · 2 comments
Closed
Milestone

Comments

@blixt
Copy link
Contributor

blixt commented Jan 9, 2019

What version of Go are you using (go version)?

$ go version
go version devel +5efe9a8f11 Wed Jan 9 07:21:16 2019 +0000 darwin/amd64

Does this issue reproduce with the latest release?

No, this is an issue for a merged but unreleased change.

What operating system and processor architecture are you using (go env)?

N/A

What did you do?

rproxy := httputil.NewSingleHostReverseProxy(backURL)
rproxy.ModifyResponse = func(resp *http.Response) error {
	resp.Header.Set("X-Important-Header", "HelloWorld")
	return nil
}

req, _ := http.NewRequest("GET", frontendProxy.URL, nil)
req.Header.Set("Connection", "Upgrade")
req.Header.Set("Upgrade", "websocket")

c := frontendProxy.Client()
res, err := c.Do(req)

if res.Header.Get("X-Important-Header") != "HelloWorld" {
	t.Fatalf("missing/invalid custom header; got %#v", res.Header)
}

Full runnable test code: https://gist.github.com/blixt/48f4581437eab9863b977ca7dc3001af

What did you expect to see?

The custom header.

What did you see instead?

--- FAIL: TestReverseProxyWebSocketModifyResponse (0.00s)
    httputil_test.go:67: missing/invalid custom header; got http.Header{"Connection":[]string{"upgrade"}, "Upgrade":[]string{"WebSocket"}}

Remarks

Obviously the ModifyResponse function cannot do anything with Body so the web socket path would ideally clear the Body field in the response, and make sure it's still nil after calling ModifyResponse.

@bradfitz bradfitz self-assigned this Jan 9, 2019
@bradfitz bradfitz added this to the Go1.12 milestone Jan 9, 2019
@bradfitz
Copy link
Contributor

bradfitz commented Jan 9, 2019

Thanks! I'll send a fix for Go 1.12.

/cc @ianlancetaylor @dmitshur

@gopherbot
Copy link

Change https://golang.org/cl/157098 mentions this issue: net/http/httputil: run the ReverseProxy.ModifyResponse hook for upgrades

@golang golang locked and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants