@@ -78,15 +78,13 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
78
78
79
79
// Pass headers from the incoming request to the dialer to forward them to
80
80
// the final destinations.
81
- h := http.Header {}
82
- h .Add ("Origin" , req .Header .Get ("Origin" ))
83
- protocols := req .Header [http .CanonicalHeaderKey ("Sec-WebSocket-Protocol" )]
84
- for _ , prot := range protocols {
85
- h .Add ("Sec-WebSocket-Protocol" , prot )
81
+ requestHeader := http.Header {}
82
+ requestHeader .Add ("Origin" , req .Header .Get ("Origin" ))
83
+ for _ , prot := range req .Header [http .CanonicalHeaderKey ("Sec-WebSocket-Protocol" )] {
84
+ requestHeader .Add ("Sec-WebSocket-Protocol" , prot )
86
85
}
87
- cookies := req .Header [http .CanonicalHeaderKey ("Cookie" )]
88
- for _ , cookie := range cookies {
89
- h .Add ("Cookie" , cookie )
86
+ for _ , cookie := range req .Header [http .CanonicalHeaderKey ("Cookie" )] {
87
+ requestHeader .Add ("Cookie" , cookie )
90
88
}
91
89
92
90
// Pass X-Forwarded-For headers too, code below is a part of
@@ -100,23 +98,24 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
100
98
if prior , ok := req .Header ["X-Forwarded-For" ]; ok {
101
99
clientIP = strings .Join (prior , ", " ) + ", " + clientIP
102
100
}
103
- h .Set ("X-Forwarded-For" , clientIP )
101
+ requestHeader .Set ("X-Forwarded-For" , clientIP )
104
102
}
105
103
106
104
// Set the originating protocol of the incoming HTTP request. The SSL might
107
105
// be terminated on our site and because we doing proxy adding this would
108
106
// be helpful for applications on the backend.
109
- h .Set ("X-Forwarded-Proto" , "http" )
107
+ requestHeader .Set ("X-Forwarded-Proto" , "http" )
110
108
if req .TLS != nil {
111
- h .Set ("X-Forwarded-Proto" , "https" )
109
+ requestHeader .Set ("X-Forwarded-Proto" , "https" )
112
110
}
113
111
114
- // Connect to the backend URL, also pass the headers we prepared above.
112
+ // Connect to the backend URL, also pass the headers we get from the requst
113
+ // together with the Forwarded headers we prepared above.
115
114
// TODO: support multiplexing on the same backend connection instead of
116
115
// opening a new TCP connection time for each request. This should be
117
116
// optional:
118
117
// http://tools.ietf.org/html/draft-ietf-hybi-websocket-multiplexing-01
119
- connBackend , resp , err := dialer .Dial (backendURL .String (), h )
118
+ connBackend , resp , err := dialer .Dial (backendURL .String (), requestHeader )
120
119
if err != nil {
121
120
log .Printf ("websocketproxy: couldn't dial to remote backend url %s\n " , err )
122
121
return
0 commit comments