requestbody: Fix ContentLength calculation after body replacement (#6896)

This commit is contained in:
Steffen Busch 2025-03-12 23:18:02 +01:00 committed by GitHub
parent dccf3d8982
commit 2ac09fdb20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -75,7 +75,7 @@ func (rb RequestBody) ServeHTTP(w http.ResponseWriter, r *http.Request, next cad
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer) repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
replacedBody := repl.ReplaceAll(rb.Set, "") replacedBody := repl.ReplaceAll(rb.Set, "")
r.Body = io.NopCloser(strings.NewReader(replacedBody)) r.Body = io.NopCloser(strings.NewReader(replacedBody))
r.ContentLength = int64(len(rb.Set)) r.ContentLength = int64(len(replacedBody))
} }
if r.Body == nil { if r.Body == nil {
return next.ServeHTTP(w, r) return next.ServeHTTP(w, r)