package deconnector import ( "bufio" "context" "fmt" "net" "net/http" ) func (d *Deconnector) handleDeconnect(ctx context.Context, clientConn net.Conn, connectReq *http.Request) { // 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 { d.app.Logger().WithError(err). Error("Failed to read inner request after CONNECT:80") 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(ctx, clientConn, innerReq) }