add src field for logger and recorder

This commit is contained in:
ginuerzh
2025-07-02 21:35:02 +08:00
parent 97ed5080a6
commit d9a2f44a78
27 changed files with 217 additions and 92 deletions
+10 -2
View File
@@ -229,8 +229,9 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
ro.Host = addr
fields := map[string]any{
"dst": addr,
"host": addr,
"dst": addr,
"host": addr,
"network": network,
}
if u, _, _ := h.basicProxyAuth(req.Header.Get("Proxy-Authorization")); u != "" {
@@ -288,6 +289,9 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
return errors.New("authentication failed")
}
log = log.WithFields(map[string]any{"clientID": clientID})
ro.ClientID = clientID
if resp.Header.Get("Proxy-Agent") == "" {
resp.Header.Set("Proxy-Agent", h.md.proxyAgent)
}
@@ -354,6 +358,10 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
}
defer cc.Close()
log = log.WithFields(map[string]any{"src": cc.LocalAddr().String(), "dst": cc.RemoteAddr().String()})
ro.Src = cc.LocalAddr().String()
ro.Dst = cc.RemoteAddr().String()
resp.StatusCode = http.StatusOK
resp.Status = "200 Connection established"
+3
View File
@@ -63,6 +63,9 @@ func (h *httpHandler) handleUDP(ctx context.Context, conn net.Conn, ro *xrecorde
}
defer c.Close()
log.WithFields(map[string]any{"src": c.LocalAddr().String()})
ro.Src = c.LocalAddr().String()
pc, ok := c.(net.PacketConn)
if !ok {
err = errors.New("wrong connection type")