Skip to content

Commit 51d2890

Browse files
committed
Merge pull request #3 from databus23/patch-1
Avoid passing empty headers during upgrade
2 parents f90542e + 11b9896 commit 51d2890

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

websocketproxy.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
136136

137137
// Only pass those headers to the upgrader.
138138
upgradeHeader := http.Header{}
139-
upgradeHeader.Set("Sec-WebSocket-Protocol",
140-
resp.Header.Get(http.CanonicalHeaderKey("Sec-WebSocket-Protocol")))
141-
upgradeHeader.Set("Set-Cookie",
142-
resp.Header.Get(http.CanonicalHeaderKey("Set-Cookie")))
139+
if hdr := resp.Header.Get("Sec-Websocket-Protocol"); hdr != "" {
140+
upgradeHeader.Set("Sec-Websocket-Protocol", hdr)
141+
}
142+
if hdr := resp.Header.Get("Set-Cookie"); hdr != "" {
143+
upgradeHeader.Set("Set-Cookie", hdr)
144+
}
143145

144146
// Now upgrade the existing incoming request to a WebSocket connection.
145147
// Also pass the header that we gathered from the Dial handshake.

0 commit comments

Comments
 (0)