From 112b3e5a6c254cb293bb616604c9db6e254b8f1e Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Thu, 12 Sep 2019 10:22:09 +0800 Subject: [PATCH] Fix: don't close connection on status `100 Continue` and header `Proxy-Connection: Keep-Alive` (#294) --- tunnel/connection.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tunnel/connection.go b/tunnel/connection.go index 327a1c6..b5beb04 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -37,7 +37,16 @@ func (t *Tunnel) handleHTTP(request *adapters.HTTPAdapter, outbound net.Conn) { break } adapters.RemoveHopByHopHeaders(resp.Header) - if resp.ContentLength >= 0 { + + if resp.StatusCode == http.StatusContinue { + err = resp.Write(request) + if err != nil { + break + } + goto handleResponse + } + + if keepAlive || resp.ContentLength >= 0 { resp.Header.Set("Proxy-Connection", "keep-alive") resp.Header.Set("Connection", "keep-alive") resp.Header.Set("Keep-Alive", "timeout=4") @@ -50,14 +59,6 @@ func (t *Tunnel) handleHTTP(request *adapters.HTTPAdapter, outbound net.Conn) { break } - if !keepAlive { - break - } - - if resp.StatusCode == http.StatusContinue { - goto handleResponse - } - req, err = http.ReadRequest(inboundReeder) if err != nil { break