Skip to content

Commit

Permalink
Merge pull request koding#28 from wbutler1331/master
Browse files Browse the repository at this point in the history
Preserve host header
  • Loading branch information
rjeczalik committed Dec 20, 2018
2 parents 0fa3f99 + 1458be2 commit 7ed82d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions websocketproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
for _, cookie := range req.Header[http.CanonicalHeaderKey("Cookie")] {
requestHeader.Add("Cookie", cookie)
}
if req.Host != "" {
requestHeader.Set("Host", req.Host)
}

// Pass X-Forwarded-For headers too, code below is a part of
// httputil.ReverseProxy. See http://en.wikipedia.org/wiki/X-Forwarded-For
Expand Down
6 changes: 6 additions & 0 deletions websocketproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func TestProxy(t *testing.T) {
go func() {
mux2 := http.NewServeMux()
mux2.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// Don't upgrade if original host header isn't preserved
if r.Host != "127.0.0.1:7777" {
log.Printf("Host header set incorrectly. Expecting 127.0.0.1:7777 got %s", r.Host)
return
}

conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Println(err)
Expand Down

0 comments on commit 7ed82d8

Please sign in to comment.