Skip to content

Commit

Permalink
calling Hijack in handleHttps if defined
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanz committed May 31, 2023
1 parent fff8ef1 commit f0e6940
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions https.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request
return
}
ctx.Logf("Accepting CONNECT to %s", host)
proxyClient.Write([]byte("HTTP/1.0 200 Connection established\r\n\r\n"))
if todo.Hijack != nil {
todo.Hijack(r, proxyClient, ctx)
} else {
proxyClient.Write([]byte("HTTP/1.0 200 Connection established\r\n\r\n"))
}

targetTCP, targetOK := targetSiteCon.(halfClosable)
proxyClientTCP, clientOK := proxyClient.(halfClosable)
Expand All @@ -156,7 +160,11 @@ func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request
case ConnectHijack:
todo.Hijack(r, proxyClient, ctx)
case ConnectHTTPMitm:
proxyClient.Write([]byte("HTTP/1.0 200 OK\r\n\r\n"))
if todo.Hijack != nil {
todo.Hijack(r, proxyClient, ctx)
} else {
proxyClient.Write([]byte("HTTP/1.0 200 OK\r\n\r\n"))
}
ctx.Logf("Assuming CONNECT is plain HTTP tunneling, mitm proxying it")
targetSiteCon, err := proxy.connectDial(ctx, "tcp", host)
if err != nil {
Expand Down Expand Up @@ -193,7 +201,11 @@ func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request
}
}
case ConnectMitm:
proxyClient.Write([]byte("HTTP/1.0 200 OK\r\n\r\n"))
if todo.Hijack != nil {
todo.Hijack(r, proxyClient, ctx)
} else {
proxyClient.Write([]byte("HTTP/1.0 200 OK\r\n\r\n"))
}
ctx.Logf("Assuming CONNECT is TLS, mitm proxying it")
// this goes in a separate goroutine, so that the net/http server won't think we're
// still handling the request even after hijacking the connection. Those HTTP CONNECT
Expand Down

0 comments on commit f0e6940

Please sign in to comment.