From 9e268129e35d36e8722574c7ff0fbd0304974e36 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Thu, 22 Mar 2018 09:11:13 +0100 Subject: [PATCH] Issue #421: Close websocket connection on failure The websocket proxy is implemented as a raw tcp proxy which relies on the client and server to close the connection. When a websocket upgrade fails the upstream server may keep the connection open. If a proxy like nginx is used in front of fabio it will keep its connection to fabio open effectively establishing a direct channel between nginx and the upstream server which will be used for any request forwarded by nginx to fabio. Adding a 'Connection: close' header to the upstream request should indicate to the server to close the connection. If that works then we can keep the raw tcp proxy for websockets. Otherwise, fabio needs to handle the handshake and close the connection itself. Fixes #421 --- proxy/http_proxy.go | 1 + 1 file changed, 1 insertion(+) diff --git a/proxy/http_proxy.go b/proxy/http_proxy.go index b531373af..a19cb2a63 100644 --- a/proxy/http_proxy.go +++ b/proxy/http_proxy.go @@ -162,6 +162,7 @@ func (p *HTTPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { } else { h = newRawProxy(targetURL.Host, net.Dial) } + r.Header.Set("Connection", "close") case accept == "text/event-stream": // use the flush interval for SSE (server-sent events)