mirror of
https://github.com/usestrix/strix.git
synced 2026-10-13 03:57:59 +00:00
resolve(proxy): emit Content-Length: 0 for empty replaced body
build_raw_request's Content-Length guard was "if body and ...", so a falsy empty-string body (a valid replacement via repeat_request's modifications["body"]) skipped Content-Length injection entirely. Sending no Content-Length is valid HTTP/1.1, but some strict servers or WAFs expect an explicit Content-Length: 0, so silently omitting it can still cause inconsistent replay behavior. Change the guard to "body is not None" so an empty body still gets Content-Length: 0 while a None body (not applicable here, but kept for clarity) is still skipped. Adds test_build_raw_request_sets_content_length_zero_for_empty_body, verified RED against the prior "if body and ..." guard before GREEN. Addresses review feedback from usestrix/strix#614.
This commit is contained in:
parent
f4d2aea432
commit
453aabe59d
2 changed files with 18 additions and 1 deletions
|
|
@ -157,7 +157,7 @@ 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}:
|
||||
if body is not None and "Content-Length" not in {k.title() for k in final_headers}:
|
||||
final_headers["Content-Length"] = str(len(body.encode("utf-8")))
|
||||
|
||||
lines = [f"{method.upper()} {path} HTTP/1.1"]
|
||||
|
|
|
|||
|
|
@ -60,3 +60,20 @@ def test_build_raw_request_recomputes_content_length_after_replacement() -> None
|
|||
)
|
||||
head = raw.decode("utf-8").split("\r\n\r\n", 1)[0]
|
||||
assert f"Content-Length: {len(new_body.encode('utf-8'))}" in head
|
||||
|
||||
|
||||
def test_build_raw_request_sets_content_length_zero_for_empty_body() -> None:
|
||||
components = _components(body="old")
|
||||
modified = apply_modifications(
|
||||
components,
|
||||
{"body": ""},
|
||||
"http://example.com/submit",
|
||||
)
|
||||
_, raw = build_raw_request(
|
||||
method=modified["method"],
|
||||
url=modified["url"],
|
||||
headers=modified["headers"],
|
||||
body=modified["body"],
|
||||
)
|
||||
head = raw.decode("utf-8").split("\r\n\r\n", 1)[0]
|
||||
assert "Content-Length: 0" in head
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue