diff --git a/proxy/helper.go b/proxy/helper.go index 4778404..142dabb 100644 --- a/proxy/helper.go +++ b/proxy/helper.go @@ -38,7 +38,7 @@ func LogErr(log *_log.Entry, err error) (loged bool) { // 转发流量 // Read a => Write b // Read b => Write a -func Transfer(log *_log.Entry, a, b io.ReadWriteCloser) { +func transfer(log *_log.Entry, a, b io.ReadWriteCloser) { done := make(chan struct{}) defer close(done) diff --git a/proxy/middle.go b/proxy/middle.go index b71ce45..c2a30d0 100644 --- a/proxy/middle.go +++ b/proxy/middle.go @@ -7,7 +7,6 @@ import ( "net" "net/http" "strings" - "time" "github.com/lqqyt2423/go-mitmproxy/cert" "github.com/lqqyt2423/go-mitmproxy/flow" @@ -89,8 +88,8 @@ func NewMiddle(proxy *Proxy, caPath string) (Interceptor, error) { } server := &http.Server{ - Handler: m, - IdleTimeout: 5 * time.Second, + Handler: m, + // IdleTimeout: 5 * time.Second, ConnContext: func(ctx context.Context, c net.Conn) context.Context { return context.WithValue(ctx, flow.ConnContextKey, c.(*tls.Conn).NetConn().(*pipeConn).connContext) @@ -115,6 +114,7 @@ func (m *Middle) Start() error { return m.Server.ServeTLS(m.Listener, "", "") } +// todo: should block until ServerConnected func (m *Middle) Dial(req *http.Request) (net.Conn, error) { pipeClientConn, pipeServerConn := newPipes(req) go m.intercept(pipeServerConn) diff --git a/proxy/proxy.go b/proxy/proxy.go index 8901288..d1d9f2a 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -369,9 +369,7 @@ func (proxy *Proxy) handleConnect(res http.ResponseWriter, req *http.Request) { // cconn.(*net.TCPConn).SetLinger(0) // send RST other than FIN when finished, to avoid TIME_WAIT state // cconn.(*net.TCPConn).SetKeepAlive(false) - defer func() { - cconn.Close() - }() + defer cconn.Close() _, err = io.WriteString(cconn, "HTTP/1.1 200 Connection Established\r\n\r\n") if err != nil { @@ -379,5 +377,5 @@ func (proxy *Proxy) handleConnect(res http.ResponseWriter, req *http.Request) { return } - Transfer(log, conn, cconn) + transfer(log, conn, cconn) } diff --git a/proxy/websocket.go b/proxy/websocket.go index a03d3b3..f2a50ff 100644 --- a/proxy/websocket.go +++ b/proxy/websocket.go @@ -24,7 +24,7 @@ func (s *WebSocket) WS(conn net.Conn, host string) { return } defer remoteConn.Close() - Transfer(log, conn, remoteConn) + transfer(log, conn, remoteConn) } func (s *WebSocket) WSS(res http.ResponseWriter, req *http.Request) { @@ -61,5 +61,5 @@ func (s *WebSocket) WSS(res http.ResponseWriter, req *http.Request) { log.Errorf("wss upgrade: %v\n", err) return } - Transfer(log, conn, cconn) + transfer(log, conn, cconn) }