Browse Source

only keep connection alive when content length is known

Darien Raymond 8 năm trước cách đây
mục cha
commit
18904e9adb
1 tập tin đã thay đổi với 6 bổ sung4 xóa
  1. 6 4
      proxy/http/server.go

+ 6 - 4
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{