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

Support for forwarding end-to-end headers #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion websocketproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,26 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {

// Pass headers from the incoming request to the dialer to forward them to
// the final destinations.
requestHeader := http.Header{}
requestHeader := req.Header.Clone()

// gorilla/websocket automatically adds these headers back when Dial() is called, but it never
// uses Set(), rather it sets these headers using normal assignment might can so lead to
// duplicate headers. Hence, we can remove them. (If this problem gets fixed in gorilla/websocket,
// these 5 lines become redundant, but will not break the current implementation)
requestHeader.Del("Connection")
requestHeader.Del("Sec-Websocket-Extensions")
requestHeader.Del("Sec-Websocket-Key")
requestHeader.Del("Sec-Websocket-Version")
requestHeader.Del("Upgrade")

// Remove all hop-by-hop headers
requestHeader.Del("Keep-Alive")
requestHeader.Del("Transfer-Encoding")
requestHeader.Del("TE")
requestHeader.Del("Trailer")
requestHeader.Del("Proxy-Authorization")
requestHeader.Del("Proxy-Authenticate")

if origin := req.Header.Get("Origin"); origin != "" {
requestHeader.Add("Origin", origin)
}
Expand Down