From 11bca5bc3d6bae647cc25a877ad6b34a8026d328 Mon Sep 17 00:00:00 2001 From: wzxjohn Date: Wed, 29 Jan 2025 23:06:09 +0800 Subject: [PATCH] fix(http): set Proxy-Agent header after authenticate to avoid leak #42 --- handler/http/handler.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/handler/http/handler.go b/handler/http/handler.go index e0581e76..89b0b98e 100644 --- a/handler/http/handler.go +++ b/handler/http/handler.go @@ -254,9 +254,6 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt if resp.Header == nil { resp.Header = http.Header{} } - if resp.Header.Get("Proxy-Agent") == "" { - resp.Header.Set("Proxy-Agent", h.md.proxyAgent) - } ro.HTTP = &xrecorder.HTTPRecorderObject{ Host: req.Host, @@ -290,6 +287,14 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt if !ok { return errors.New("authentication failed") } + + if resp.Header == nil { + resp.Header = http.Header{} + } + if resp.Header.Get("Proxy-Agent") == "" { + resp.Header.Set("Proxy-Agent", h.md.proxyAgent) + } + ctx = ctxvalue.ContextWithClientID(ctx, ctxvalue.ClientID(clientID)) if h.options.Bypass != nil &&