From 52cfa946522067c170084c89fc31c85cc25915e8 Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Sat, 26 Oct 2019 22:12:33 +0800 Subject: [PATCH] Fix: HTTP proxy should copy body --- tunnel/connection.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tunnel/connection.go b/tunnel/connection.go index e48167f2..1f9f335b 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -36,6 +36,7 @@ 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 +60,13 @@ func (t *Tunnel) handleHTTP(request *adapters.HTTPAdapter, outbound net.Conn) { break } + buf := pool.BufPool.Get().([]byte) + _, err = io.CopyBuffer(request, resp.Body, buf) + pool.BufPool.Put(buf[:cap(buf)]) + if err != nil && err != io.EOF { + break + } + req, err = http.ReadRequest(inboundReeder) if err != nil { break