mirror of
https://github.com/fosrl/newt.git
synced 2026-04-10 11:56:37 +00:00
Basic http is working
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user