Fix: don't keepalive when connection is close (#65)

fixed #60
This commit is contained in:
beyondkmp 2018-12-10 11:48:57 +08:00 committed by Dreamacro
parent 5e4b35e03a
commit 34c8655974

View file

@ -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