diff --git a/proxy/http_proxy.go b/proxy/http_proxy.go index b531373af..49ef857e3 100644 --- a/proxy/http_proxy.go +++ b/proxy/http_proxy.go @@ -156,11 +156,11 @@ func (p *HTTPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { case upgrade == "websocket" || upgrade == "Websocket": r.URL = targetURL if targetURL.Scheme == "https" || targetURL.Scheme == "wss" { - h = newRawProxy(targetURL.Host, func(network, address string) (net.Conn, error) { + h = newWSHandler(targetURL.Host, func(network, address string) (net.Conn, error) { return tls.Dial(network, address, tr.(*http.Transport).TLSClientConfig) }) } else { - h = newRawProxy(targetURL.Host, net.Dial) + h = newWSHandler(targetURL.Host, net.Dial) } case accept == "text/event-stream": diff --git a/proxy/http_raw_handler.go b/proxy/ws_handler.go similarity index 89% rename from proxy/http_raw_handler.go rename to proxy/ws_handler.go index f13f4f7fe..35c8710a6 100644 --- a/proxy/http_raw_handler.go +++ b/proxy/ws_handler.go @@ -16,10 +16,11 @@ var conn = metrics.DefaultRegistry.GetCounter("ws.conn") type dialFunc func(network, address string) (net.Conn, error) -// newRawProxy returns an HTTP handler which forwards data between -// an incoming and outgoing TCP connection including the original request. -// This handler establishes a new outgoing connection per request. -func newRawProxy(host string, dial dialFunc) http.Handler { +// newWSHandler returns an HTTP handler which forwards data between +// an incoming and outgoing Websocket connection. It checks whether +// the handshake was completed successfully before forwarding data +// between the client and server. +func newWSHandler(host string, dial dialFunc) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { conn.Inc(1) defer func() { conn.Inc(-1) }()