2026-05-26 16:32:55 +03:00
|
|
|
package deconnector
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"fmt"
|
|
|
|
|
"net"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (d *Deconnector) handleDeconnect(clientConn net.Conn, connectReq *http.Request, upstreamURL *url.URL) {
|
|
|
|
|
// Tell client the tunnel is open
|
|
|
|
|
fmt.Fprintf(clientConn, "HTTP/1.1 200 Connection established\r\n\r\n")
|
|
|
|
|
|
|
|
|
|
// Read the real HTTP request the client sends through the tunnel
|
|
|
|
|
innerReq, err := http.ReadRequest(bufio.NewReader(clientConn))
|
|
|
|
|
if err != nil {
|
2026-05-26 18:39:45 +03:00
|
|
|
d.app.Logger().WithError(err).
|
|
|
|
|
Error("Failed to read inner request after CONNECT:80")
|
|
|
|
|
|
2026-05-26 16:32:55 +03:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
innerReq.URL.Scheme = "http"
|
|
|
|
|
innerReq.URL.Host = connectReq.Host
|
|
|
|
|
innerReq.RequestURI = ""
|
|
|
|
|
|
|
|
|
|
d.app.Logger().
|
|
|
|
|
WithField("method", innerReq.Method).
|
|
|
|
|
WithField("url", innerReq.URL).
|
|
|
|
|
Info("Handling de-CONNECT request")
|
|
|
|
|
|
|
|
|
|
d.forwardHTTP(clientConn, innerReq, upstreamURL)
|
|
|
|
|
}
|