Basic http is working

This commit is contained in:
Owen
2026-04-09 11:43:26 -04:00
parent 7e1e3408d5
commit 47c646bc33
5 changed files with 320 additions and 4 deletions

View File

@@ -137,14 +137,26 @@ func (h *TCPHandler) InstallTCPHandler() error {
// handleTCPConn handles a TCP connection by proxying it to the actual target
func (h *TCPHandler) handleTCPConn(netstackConn *gonet.TCPConn, id stack.TransportEndpointID) {
defer netstackConn.Close()
// Extract source and target address from the connection ID
// Extract source and target address from the connection ID first so they
// are available for HTTP routing before any defer is set up.
srcIP := id.RemoteAddress.String()
srcPort := id.RemotePort
dstIP := id.LocalAddress.String()
dstPort := id.LocalPort
// Route to the HTTP handler when the destination port belongs to it.
// The HTTP handler takes full ownership of the connection lifecycle, so we
// must NOT install the defer close before handing the conn off.
if h.proxyHandler != nil && h.proxyHandler.httpHandler != nil {
if h.proxyHandler.httpHandler.HandlesPort(dstPort) {
logger.Info("+++++++++++++++++++++++TCP Forwarder: Routing %s:%d -> %s:%d to HTTP handler", srcIP, srcPort, dstIP, dstPort)
h.proxyHandler.httpHandler.HandleConn(netstackConn)
return
}
}
defer netstackConn.Close()
logger.Info("TCP Forwarder: Handling connection %s:%d -> %s:%d", srcIP, srcPort, dstIP, dstPort)
// Check if there's a destination rewrite for this connection (e.g., localhost targets)