Skip to content

Commit 2e6e0d3

Browse files
committed
websocketproxy: fix header variable
1 parent 9cf431a commit 2e6e0d3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

websocketproxy.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
6363
dialer = DefaultDialer
6464
}
6565

66+
// TODO: Also consider adding x-fowarded-for and x-forwarded-proto headers.
67+
6668
// Pass headers from the incoming request to the dialer to forward them to
6769
// the final destinations.
6870
h := http.Header{}
@@ -90,13 +92,13 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
9092
}
9193

9294
// Only pass those headers to the upgrader.
93-
respHeader := http.Header{}
94-
resp.Header.Add("Sec-WebSocket-Protocol", resp.Header.Get("Sec-WebSocket-Protocol"))
95-
resp.Header.Add("Set-Cookie", resp.Header.Get("Set-Cookie"))
95+
upgradeHeader := http.Header{}
96+
upgradeHeader.Add("Sec-WebSocket-Protocol", resp.Header.Get("Sec-WebSocket-Protocol"))
97+
upgradeHeader.Add("Set-Cookie", resp.Header.Get("Set-Cookie"))
9698

9799
// Now upgrade the existing incoming request to a WebSocket connection.
98-
// Also pass the responseHeader that we gathered from the Dial handshake.
99-
connPub, err := upgrader.Upgrade(rw, req, respHeader)
100+
// Also pass the header that we gathered from the Dial handshake.
101+
connPub, err := upgrader.Upgrade(rw, req, upgradeHeader)
100102
if err != nil {
101103
log.Printf("websocketproxy: couldn't upgrade %s\n", err)
102104
return
@@ -109,7 +111,7 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
109111
errc <- err
110112
}
111113

112-
// Start our proxy now, after we setup everything.
114+
// Start our proxy now, everything is ready...
113115
go cp(connBackend.UnderlyingConn(), connPub.UnderlyingConn())
114116
go cp(connPub.UnderlyingConn(), connBackend.UnderlyingConn())
115117
<-errc

0 commit comments

Comments
 (0)