Skip to content

Commit 948b6ca

Browse files
committed
Revert "Connect related changes - add optional hooks (#504)"
This reverts commit 44bab45.
1 parent 44bab45 commit 948b6ca

File tree

2 files changed

+9
-44
lines changed

2 files changed

+9
-44
lines changed

examples/cascadeproxy/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ func main() {
4141
// socks5://localhost:8082
4242
return url.Parse("http://localhost:8082")
4343
}
44-
connectReqHandler := func(req *http.Request) error {
44+
connectReqHandler := func(req *http.Request) {
4545
SetBasicAuth(username, password, req)
46-
return nil
4746
}
4847
middleProxy.ConnectDial = middleProxy.NewConnectDialToProxyWithHandler("http://localhost:8082", connectReqHandler)
4948

https.go

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,7 @@ func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request
143143
return
144144
}
145145
ctx.Logf("Accepting CONNECT to %s", host)
146-
if todo.Hijack != nil {
147-
todo.Hijack(r, proxyClient, ctx)
148-
} else {
149-
_, _ = proxyClient.Write([]byte("HTTP/1.0 200 Connection established\r\n\r\n"))
150-
}
146+
_, _ = proxyClient.Write([]byte("HTTP/1.0 200 Connection established\r\n\r\n"))
151147

152148
targetTCP, targetOK := targetSiteCon.(halfClosable)
153149
proxyClientTCP, clientOK := proxyClient.(halfClosable)
@@ -198,11 +194,7 @@ func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request
198194
case ConnectHijack:
199195
todo.Hijack(r, proxyClient, ctx)
200196
case ConnectHTTPMitm:
201-
if todo.Hijack != nil {
202-
todo.Hijack(r, proxyClient, ctx)
203-
} else {
204-
_, _ = proxyClient.Write([]byte("HTTP/1.0 200 OK\r\n\r\n"))
205-
}
197+
_, _ = proxyClient.Write([]byte("HTTP/1.0 200 OK\r\n\r\n"))
206198
ctx.Logf("Assuming CONNECT is plain HTTP tunneling, mitm proxying it")
207199

208200
var targetSiteCon net.Conn
@@ -273,11 +265,7 @@ func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request
273265
}
274266
}
275267
case ConnectMitm:
276-
if todo.Hijack != nil {
277-
todo.Hijack(r, proxyClient, ctx)
278-
} else {
279-
_, _ = proxyClient.Write([]byte("HTTP/1.0 200 OK\r\n\r\n"))
280-
}
268+
_, _ = proxyClient.Write([]byte("HTTP/1.0 200 OK\r\n\r\n"))
281269
ctx.Logf("Assuming CONNECT is TLS, mitm proxying it")
282270
// this goes in a separate goroutine, so that the net/http server won't think we're
283271
// still handling the request even after hijacking the connection. Those HTTP CONNECT
@@ -546,15 +534,7 @@ func (proxy *ProxyHttpServer) NewConnectDialToProxy(httpsProxy string) func(netw
546534

547535
func (proxy *ProxyHttpServer) NewConnectDialToProxyWithHandler(
548536
httpsProxy string,
549-
connectReqHandler func(req *http.Request) error,
550-
) func(network, addr string) (net.Conn, error) {
551-
return proxy.NewConnectDialToProxyWithMoreHandlers(httpsProxy, connectReqHandler, nil)
552-
}
553-
554-
func (proxy *ProxyHttpServer) NewConnectDialToProxyWithMoreHandlers(
555-
httpsProxy string,
556-
connectReqHandler func(req *http.Request) error,
557-
connectRespHandler func(req *http.Response) error,
537+
connectReqHandler func(req *http.Request),
558538
) func(network, addr string) (net.Conn, error) {
559539
u, err := url.Parse(httpsProxy)
560540
if err != nil {
@@ -572,9 +552,7 @@ func (proxy *ProxyHttpServer) NewConnectDialToProxyWithMoreHandlers(
572552
Header: make(http.Header),
573553
}
574554
if connectReqHandler != nil {
575-
if err := connectReqHandler(connectReq); err != nil {
576-
return nil, err
577-
}
555+
connectReqHandler(connectReq)
578556
}
579557
c, err := proxy.dial(&ProxyCtx{Req: &http.Request{}}, network, u.Host)
580558
if err != nil {
@@ -591,12 +569,7 @@ func (proxy *ProxyHttpServer) NewConnectDialToProxyWithMoreHandlers(
591569
return nil, err
592570
}
593571
defer resp.Body.Close()
594-
if connectRespHandler != nil {
595-
if err := connectRespHandler(resp); err != nil {
596-
c.Close()
597-
return nil, err
598-
}
599-
} else if resp.StatusCode != http.StatusOK {
572+
if resp.StatusCode != http.StatusOK {
600573
resp, err := io.ReadAll(io.LimitReader(resp.Body, _errorRespMaxLength))
601574
if err != nil {
602575
return nil, err
@@ -630,9 +603,7 @@ func (proxy *ProxyHttpServer) NewConnectDialToProxyWithMoreHandlers(
630603
Header: make(http.Header),
631604
}
632605
if connectReqHandler != nil {
633-
if err := connectReqHandler(connectReq); err != nil {
634-
return nil, err
635-
}
606+
connectReqHandler(connectReq)
636607
}
637608
_ = connectReq.Write(c)
638609
// Read response.
@@ -645,12 +616,7 @@ func (proxy *ProxyHttpServer) NewConnectDialToProxyWithMoreHandlers(
645616
return nil, err
646617
}
647618
defer resp.Body.Close()
648-
if connectRespHandler != nil {
649-
if err := connectRespHandler(resp); err != nil {
650-
c.Close()
651-
return nil, err
652-
}
653-
} else if resp.StatusCode != http.StatusOK {
619+
if resp.StatusCode != http.StatusOK {
654620
body, err := io.ReadAll(io.LimitReader(resp.Body, _errorRespMaxLength))
655621
if err != nil {
656622
return nil, err

0 commit comments

Comments
 (0)