fix(proxy): recompute Content-Length when replaying a modified body (#816)

build_raw_request kept the Content-Length inherited from the captured
request, so replaying a modified body (repeat_request) emitted a request
whose declared length did not match the body — truncating the payload or
stalling the target. Drop any inherited Content-Length (case-insensitively)
and recompute it from the body actually being sent.

Adds tests covering a lengthened body, an emptied body, and the
no-inherited-header path.

Fixes #814

Co-authored-by: thejesh23 <thejesh23@users.noreply.github.com>
This commit is contained in:
Thejesh Reddy
2026-07-20 21:43:49 -04:00
committed by GitHub
co-authored by thejesh23
parent 8cd9abba21
commit 599f7c7526
2 changed files with 43 additions and 1 deletions
+6 -1
View File
@@ -187,7 +187,12 @@ def build_raw_request(
final_headers = {**headers}
final_headers.setdefault("Host", parsed.netloc)
final_headers.setdefault("User-Agent", "strix")
if body and "Content-Length" not in {k.title() for k in final_headers}:
# A Content-Length inherited from the captured request describes the ORIGINAL
# body; once the body is modified for replay it is stale. Drop any inherited
# value (case-insensitively) and recompute it from the body actually being
# sent, so the replayed request is never desynced (truncated / smuggled).
final_headers = {k: v for k, v in final_headers.items() if k.title() != "Content-Length"}
if body:
final_headers["Content-Length"] = str(len(body.encode("utf-8")))
lines = [f"{method.upper()} {path} HTTP/1.1"]