From 34c86559740a1e7b54fb6bd87ae593e0cc30e416 Mon Sep 17 00:00:00 2001 From: beyondkmp Date: Mon, 10 Dec 2018 11:48:57 +0800 Subject: [PATCH] Fix: don't keepalive when connection is close (#65) fixed #60 --- tunnel/connection.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tunnel/connection.go b/tunnel/connection.go index 29061eb3..b2271d57 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -5,6 +5,7 @@ import ( "io" "net" "net/http" + "strings" "sync" "time" @@ -25,8 +26,13 @@ func (t *Tunnel) handleHTTP(request *adapters.HTTPAdapter, proxy C.ProxyAdapter) conn := newTrafficTrack(proxy.Conn(), t.traffic) req := request.R host := req.Host + keepalive := true for { + if strings.ToLower(req.Header.Get("Connection")) == "close" { + keepalive = false + } + req.Header.Set("Connection", "close") req.RequestURI = "" adapters.RemoveHopByHopHeaders(req.Header) @@ -53,6 +59,10 @@ func (t *Tunnel) handleHTTP(request *adapters.HTTPAdapter, proxy C.ProxyAdapter) break } + if !keepalive { + break + } + req, err = http.ReadRequest(bufio.NewReader(request.Conn())) if err != nil { break