Skip to content

Commit

Permalink
Inject host and enable insecure skip verification
Browse files Browse the repository at this point in the history
  • Loading branch information
alinz committed Aug 29, 2024
1 parent e816308 commit 3a21e6b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,29 @@ func (s *Server) handleWebSocket(w http.ResponseWriter, r *http.Request, contain
Path: r.URL.Path,
}

host := r.Host

for k, v := range container.Meta.Static.Headers {
key := strings.ToUpper(k)
if key == "HOST" {
host = v
break
}
}

clientConn, _, err := websocket.Dial(r.Context(), targetURL.String(), &websocket.DialOptions{
HTTPHeader: r.Header,
Host: host,
})
if err != nil {
http.Error(w, fmt.Sprintf("Error connecting to backend server: %s", err), http.StatusInternalServerError)
return
}
defer clientConn.Close(websocket.StatusNormalClosure, "")

serverConn, err := websocket.Accept(w, r, nil)
serverConn, err := websocket.Accept(w, r, &websocket.AcceptOptions{
InsecureSkipVerify: true,
})
if err != nil {
http.Error(w, fmt.Sprintf("Error connecting to backend server: %s", err), http.StatusInternalServerError)
return
Expand Down

0 comments on commit 3a21e6b

Please sign in to comment.