The Fix
Upgrade to version 0.13.2 or later.
Based on closed encode/httpx issue #987 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -616,6 +616,9 @@ def prepare(self) -> None:
has_host = "host" in self.headers
+ has_content_length = (
+ "content-length" in self.headers or "transfer-encoding" in self.headers
+ )
import requests
import httpx
for client in (requests, httpx):
for method in ("get", "head", "delete", "post", "put", "patch"):
r = client.request(method, f"https://httpbin.org/headers")
print(
f"[{client.__name__}] method={method.upper()} "
f'Content-Length={r.request.headers.get("Content-Length")}'
)
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\nUpgrade to version 0.13.2 or later.\nWhen NOT to use: Do not apply this fix if the server does not require Content-Length for empty payloads.\n\n
Why This Fix Works in Production
- Trigger: Content-Length header is missing in POST/DELETE/PUT/PATCH requests without body
- Mechanism: Content-Length header is not added for POST, PUT, and PATCH requests without a body
- Why the fix works: Add 'Content-Length: 0' on POST, PUT, PATCH if required. (first fixed release: 0.13.2).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Content-Length header is not added for POST, PUT, and PATCH requests without a body
- Production symptom (often without a traceback): Content-Length header is missing in POST/DELETE/PUT/PATCH requests without body
Proof / Evidence
- GitHub issue: #987
- Fix PR: https://github.com/encode/httpx/pull/995
- First fixed release: 0.13.2
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.53
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“I believe this is a bug as we're not following the RFC: > A user agent SHOULD send a Content-Length in a request message when…”
“I’d suggest auto including it in Request.prepare, if the method requires one, and none is currently present.”
“^Sounds good to me too — let the content stream not return a Content-Length if there's no body, and add a default Content-Length: 0 in…”
“We should cover POST, PUT, and PATCH here”
Failure Signature (Search String)
- Content-Length header is missing in POST/DELETE/PUT/PATCH requests without body
- I am not sure how to classify this issue: it could be a bug, since it is an incompatible with `requests`, on the other hand, it could be feature request, if you consider it is not
Copy-friendly signature
Failure Signature
-----------------
Content-Length header is missing in POST/DELETE/PUT/PATCH requests without body
I am not sure how to classify this issue: it could be a bug, since it is an incompatible with `requests`, on the other hand, it could be feature request, if you consider it is not that important. So, I decided to go with question. :D
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Content-Length header is missing in POST/DELETE/PUT/PATCH requests without body
I am not sure how to classify this issue: it could be a bug, since it is an incompatible with `requests`, on the other hand, it could be feature request, if you consider it is not that important. So, I decided to go with question. :D
Minimal Reproduction
import requests
import httpx
for client in (requests, httpx):
for method in ("get", "head", "delete", "post", "put", "patch"):
r = client.request(method, f"https://httpbin.org/headers")
print(
f"[{client.__name__}] method={method.upper()} "
f'Content-Length={r.request.headers.get("Content-Length")}'
)
What Broke
Requests to the server fail with a 411 Client Error when no Content-Length is present.
Why It Broke
Content-Length header is not added for POST, PUT, and PATCH requests without a body
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.13.2 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/encode/httpx/pull/995
First fixed release: 0.13.2
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not apply this fix if the server does not require Content-Length for empty payloads.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
- Upgrade behind a canary and run integration tests against the canary before 100% rollout.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.13.2 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.