From c929ad07887856ea46f354332b439fdfd113beef Mon Sep 17 00:00:00 2001 From: li Date: Tue, 14 Jul 2026 21:05:45 +0800 Subject: [PATCH] fix: clone fhttp response headers to prevent mutation aliasing fromFHTTPResponse returned Header and Trailer maps that aliased the original fhttp.Response maps. Downstream consumers (e.g. console adapter calling Header.Del) mutated the shared maps, corrupting the fhttp response state. Clone all shared data structures (Header, Trailer, TransferEncoding) to isolate the two responses. --- backend/internal/infra/egress/tlsclient.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/internal/infra/egress/tlsclient.go b/backend/internal/infra/egress/tlsclient.go index e37c367a..0f7d011c 100644 --- a/backend/internal/infra/egress/tlsclient.go +++ b/backend/internal/infra/egress/tlsclient.go @@ -56,19 +56,19 @@ func (c *browserClient) Do(request *http.Request) (*http.Response, error) { } func fromFHTTPResponse(fresponse *fhttp.Response) *http.Response { - header := http.Header(fresponse.Header) + header := http.Header(fresponse.Header).Clone() contentLength := fresponse.ContentLength if fresponse.Uncompressed { - header = header.Clone() header.Del("Content-Encoding") header.Del("Content-Length") contentLength = -1 } + transferEncoding := append([]string(nil), fresponse.TransferEncoding...) return &http.Response{ Status: fresponse.Status, StatusCode: fresponse.StatusCode, Proto: fresponse.Proto, ProtoMajor: fresponse.ProtoMajor, ProtoMinor: fresponse.ProtoMinor, Header: header, - Body: fresponse.Body, ContentLength: contentLength, TransferEncoding: fresponse.TransferEncoding, - Close: fresponse.Close, Uncompressed: fresponse.Uncompressed, Trailer: http.Header(fresponse.Trailer), + Body: fresponse.Body, ContentLength: contentLength, TransferEncoding: transferEncoding, + Close: fresponse.Close, Uncompressed: fresponse.Uncompressed, Trailer: http.Header(fresponse.Trailer).Clone(), } }