From 5c70fa7e0e983e00b48bab9402da241548d9e7a6 Mon Sep 17 00:00:00 2001 From: Steffen Busch Date: Wed, 12 Mar 2025 23:10:26 +0100 Subject: [PATCH] requestbody: Fix ContentLength calculation after body replacement --- modules/caddyhttp/requestbody/requestbody.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/caddyhttp/requestbody/requestbody.go b/modules/caddyhttp/requestbody/requestbody.go index a4518a5b4..1fa654811 100644 --- a/modules/caddyhttp/requestbody/requestbody.go +++ b/modules/caddyhttp/requestbody/requestbody.go @@ -75,7 +75,7 @@ func (rb RequestBody) ServeHTTP(w http.ResponseWriter, r *http.Request, next cad repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer) replacedBody := repl.ReplaceAll(rb.Set, "") r.Body = io.NopCloser(strings.NewReader(replacedBody)) - r.ContentLength = int64(len(rb.Set)) + r.ContentLength = int64(len(replacedBody)) } if r.Body == nil { return next.ServeHTTP(w, r)