From 981501013194772dd77168ebd014a20aaf1a7734 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Sun, 8 Sep 2019 11:21:28 +0800 Subject: [PATCH] Fix: HTTP status code `100 Continue` support" (#288) * Fix: HTTP Status Code `100 Continue` support * Style: code style adjustment --- tunnel/connection.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tunnel/connection.go b/tunnel/connection.go index 36c698d2..327a1c6c 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -17,6 +17,9 @@ func (t *Tunnel) handleHTTP(request *adapters.HTTPAdapter, outbound net.Conn) { req := request.R host := req.Host + inboundReeder := bufio.NewReader(request) + outboundReeder := bufio.NewReader(conn) + for { keepAlive := strings.TrimSpace(strings.ToLower(req.Header.Get("Proxy-Connection"))) == "keep-alive" @@ -27,8 +30,9 @@ func (t *Tunnel) handleHTTP(request *adapters.HTTPAdapter, outbound net.Conn) { if err != nil { break } - br := bufio.NewReader(conn) - resp, err := http.ReadResponse(br, req) + + handleResponse: + resp, err := http.ReadResponse(outboundReeder, req) if err != nil { break } @@ -50,7 +54,11 @@ func (t *Tunnel) handleHTTP(request *adapters.HTTPAdapter, outbound net.Conn) { break } - req, err = http.ReadRequest(bufio.NewReader(request)) + if resp.StatusCode == http.StatusContinue { + goto handleResponse + } + + req, err = http.ReadRequest(inboundReeder) if err != nil { break }