From 18904e9adbb4757f81cd7b2f00452d78df70be99 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Tue, 18 Apr 2017 13:39:34 +0200 Subject: [PATCH] only keep connection alive when content length is known --- proxy/http/server.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/proxy/http/server.go b/proxy/http/server.go index 9ee768d75..628753c84 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -236,10 +236,12 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, rea response, err := http.ReadResponse(responseReader, request) if err == nil { StripHopByHopHeaders(response.Header) - response.Header.Set("Proxy-Connection", "keep-alive") - response.Header.Set("Connection", "keep-alive") - response.Header.Set("Keep-Alive", "timeout=4") - response.Close = false + if response.ContentLength >= 0 { + response.Header.Set("Proxy-Connection", "keep-alive") + response.Header.Set("Connection", "keep-alive") + response.Header.Set("Keep-Alive", "timeout=4") + response.Close = false + } } else { log.Trace(newError("failed to read response from ", request.Host).Base(err).AtWarning()) response = &http.Response{