fix(forwarder/sniffer_http): clone response header map and sync request header to recorder
Fix two data races in Sniffer.httpRoundTrip: - resp.Header was assigned directly to ro.HTTP.Response.Header without cloning, creating shared mutable state between the response and recorder. - httpSettings.RequestHeader was set on req.Header but not propagated to ro.HTTP.Request.Header, causing the recorder to miss configured headers.
This commit is contained in:
@@ -311,6 +311,7 @@ func (h *Sniffer) httpRoundTrip(ctx context.Context, rw, cc io.ReadWriteCloser,
|
|||||||
}
|
}
|
||||||
for k, v := range httpSettings.RequestHeader {
|
for k, v := range httpSettings.RequestHeader {
|
||||||
req.Header.Set(k, v)
|
req.Header.Set(k, v)
|
||||||
|
ro.HTTP.Request.Header = req.Header.Clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, re := range httpSettings.RewriteURL {
|
for _, re := range httpSettings.RewriteURL {
|
||||||
@@ -372,7 +373,7 @@ func (h *Sniffer) httpRoundTrip(ctx context.Context, rw, cc io.ReadWriteCloser,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ro.HTTP.StatusCode = resp.StatusCode
|
ro.HTTP.StatusCode = resp.StatusCode
|
||||||
ro.HTTP.Response.Header = resp.Header
|
ro.HTTP.Response.Header = resp.Header.Clone()
|
||||||
ro.HTTP.Response.ContentLength = resp.ContentLength
|
ro.HTTP.Response.ContentLength = resp.ContentLength
|
||||||
|
|
||||||
if log.IsLevelEnabled(logger.TraceLevel) {
|
if log.IsLevelEnabled(logger.TraceLevel) {
|
||||||
|
|||||||
Reference in New Issue
Block a user