feat(forwarder/sniffer): add HTTP request body rewriting, deprecate rewriteBody in favor of rewriteResponseBody
- Add RewriteRequestBody field to HTTPNodeConfig (yaml: rewriteRequestBody) - Add RewriteRequestBody field to HTTPNodeSettings in core chain - Add rewriteReqBody function symmetric to rewriteRespBody in sniffer_rewrite.go - Wire up rewriteReqBody call in httpRoundTrip before body wrapping for recording - Add new RewriteResponseBody config field, deprecate old RewriteBody - Parse both RewriteRequestBody and RewriteResponseBody in node config parsing - Add 10 test cases covering nil, skip, content-type filter, and chained rewrites - Bump core dependency to v0.4.1 - Fix: clone response header map in internal/util/sniffing/sniffer_http.go
This commit is contained in:
@@ -290,6 +290,7 @@ func (h *Sniffer) httpRoundTrip(ctx context.Context, rw, cc io.ReadWriteCloser,
|
||||
|
||||
var responseHeader map[string]string
|
||||
var respBodyRewrites []chain.HTTPBodyRewriteSettings
|
||||
var reqBodyRewrites []chain.HTTPBodyRewriteSettings
|
||||
if httpSettings := node.Options().HTTP; httpSettings != nil {
|
||||
if auther := httpSettings.Auther; auther != nil {
|
||||
username, password, _ := req.BasicAuth()
|
||||
@@ -325,6 +326,14 @@ func (h *Sniffer) httpRoundTrip(ctx context.Context, rw, cc io.ReadWriteCloser,
|
||||
|
||||
responseHeader = httpSettings.ResponseHeader
|
||||
respBodyRewrites = httpSettings.RewriteResponseBody
|
||||
reqBodyRewrites = httpSettings.RewriteRequestBody
|
||||
}
|
||||
|
||||
// Rewrite request body before wrapping for recording,
|
||||
// so the recorder sees the rewritten content.
|
||||
if err = rewriteReqBody(req, reqBodyRewrites...); err != nil {
|
||||
log.Errorf("rewrite request body: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if bodySize := clampBodySize(h.RecorderOptions); bodySize > 0 && req.Body != nil {
|
||||
|
||||
Reference in New Issue
Block a user