mirror of
https://github.com/chenyme/grok2api.git
synced 2026-12-05 08:01:07 +00:00
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.
This commit is contained in:
1 parent
e376c2219e
commit
c929ad0788
1 file changed
+4
-4
@@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user