Files

35 lines
823 B
Go
Raw Permalink Normal View History

2026-05-26 16:32:55 +03:00
package deconnector
import (
"bufio"
2026-05-27 10:58:13 +03:00
"context"
2026-05-26 16:32:55 +03:00
"fmt"
"net"
"net/http"
)
2026-05-27 10:58:13 +03:00
func (d *Deconnector) handleDeconnect(ctx context.Context, clientConn net.Conn, connectReq *http.Request) {
2026-05-26 16:32:55 +03:00
// Tell client the tunnel is open
2026-05-27 10:58:13 +03:00
_, _ = fmt.Fprintf(clientConn, "HTTP/1.1 200 Connection established\r\n\r\n")
2026-05-26 16:32:55 +03:00
// 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")
2026-05-27 10:58:13 +03:00
d.forwardHTTP(ctx, clientConn, innerReq)
2026-05-26 16:32:55 +03:00
}