Skip to content

Commit 7338eea

Browse files
authored
Merge pull request #11 from slimsag/master
Add WebsocketProxy.Director optional function to forward additional headers
2 parents 870493f + 9f16c19 commit 7338eea

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
language: go
2-
go: 1.2
2+
go: 1.8

websocketproxy.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ var (
2727
// WebsocketProxy is an HTTP Handler that takes an incoming WebSocket
2828
// connection and proxies it to another server.
2929
type WebsocketProxy struct {
30+
// Director, if non-nil, is a function that may copy additional request
31+
// headers from the incoming WebSocket connection into the output headers
32+
// which will be forwarded to another server.
33+
Director func(incoming *http.Request, out http.Header)
34+
3035
// Backend returns the backend URL which the proxy uses to reverse proxy
3136
// the incoming WebSocket connection. Request is the initial incoming and
3237
// unmodified request.
@@ -118,6 +123,12 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
118123
requestHeader.Set("X-Forwarded-Proto", "https")
119124
}
120125

126+
// Enable the director to copy any additional headers it desires for
127+
// forwarding to the remote server.
128+
if w.Director != nil {
129+
w.Director(req, requestHeader)
130+
}
131+
121132
// Connect to the backend URL, also pass the headers we get from the requst
122133
// together with the Forwarded headers we prepared above.
123134
// TODO: support multiplexing on the same backend connection instead of

0 commit comments

Comments
 (0)