From ba7dd209fc4b3f50cc8488facf70db7df1d92c5c Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sat, 7 Dec 2019 23:37:42 +0800 Subject: [PATCH] Fix: HTTP inbound proxy can't close correctly --- tunnel/connection.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tunnel/connection.go b/tunnel/connection.go index 87faa5bd..2849bd9f 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -35,7 +35,6 @@ func (t *Tunnel) handleHTTP(request *adapters.HTTPAdapter, outbound net.Conn) { if err != nil { break } - defer resp.Body.Close() adapters.RemoveHopByHopHeaders(resp.Header) if resp.StatusCode == http.StatusContinue { @@ -59,6 +58,7 @@ func (t *Tunnel) handleHTTP(request *adapters.HTTPAdapter, outbound net.Conn) { break } + // even if resp.Write write body to the connection, but some http request have to Copy to close it buf := pool.BufPool.Get().([]byte) _, err = io.CopyBuffer(request, resp.Body, buf) pool.BufPool.Put(buf[:cap(buf)])