change middle server IdleTimeout

addon-dailer
lqqyt2423 3 years ago
parent 1b26b43670
commit 7059c4e8b3

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

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

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

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

Loading…
Cancel
Save