Skip to content

Commit

Permalink
rename raw handler to ws handler
Browse files Browse the repository at this point in the history
  • Loading branch information
magiconair committed Mar 22, 2018
1 parent 51f6471 commit ea979c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions proxy/http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
9 changes: 5 additions & 4 deletions proxy/http_raw_handler.go → proxy/ws_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }()
Expand Down

0 comments on commit ea979c9

Please sign in to comment.