The Fix
Adds test coverage for invalid content type handling and documents the expected behavior, clarifying that invalid Content-Type headers default to 'text/plain'.
Based on closed aio-libs/aiohttp issue #9522 · PR/commit linked
Production note: Watch p95/p99 latency and retry volume; timeouts can turn into retry storms and duplicate side-effects.
@@ -1474,7 +1474,12 @@ Response object
Returns value is ``'application/octet-stream'`` if no
Content-Type header present in HTTP headers according to
- :rfc:`2616`. To make sure Content-Type header is not present in
+ :rfc:`9110`. If the *Content-Type* header is invalid (e.g., ``jpg``
+ instead of ``image/jpeg``), the value is ``text/plain`` by default
from email.parser import HeaderParser
hp = HeaderParser()
hp.parsestr('Content-Type: jpg').get_content_type() # 'text/plain'
hp.parsestr('Content-Type: image/jpg').get_content_type() # 'image/jpg'
hp.parsestr('Content-Type: /jpg').get_content_type() # '/jpg'
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Apply the official fix\nAdds test coverage for invalid content type handling and documents the expected behavior, clarifying that invalid Content-Type headers default to 'text/plain'.\nWhen NOT to use: This fix does not apply if the Content-Type header is valid and correctly formatted.\n\n
Why This Fix Works in Production
- Trigger: Documentation not mentioning treatment of invalid Content-Type headers in ClientResponse (mismatch of header content and property value)
- Mechanism: Invalid Content-Type headers lead to mismatched values in ClientResponse properties
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- Shows up under Python 3.9.17 in real deployments (not just unit tests).
- Invalid Content-Type headers lead to mismatched values in ClientResponse properties
- Production symptom (often without a traceback): Documentation not mentioning treatment of invalid Content-Type headers in ClientResponse (mismatch of header content and property value)
Proof / Evidence
- GitHub issue: #9522
- Fix PR: https://github.com/aio-libs/aiohttp/pull/10880
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.70
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.64
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“### Describe the bug Recently a client script of mine received responses (status=200) for image-fetches denoting 'text/plain' in the content_type property of the response, while the body was still an image and not an error message (as would”
Failure Signature (Search String)
- Documentation not mentioning treatment of invalid Content-Type headers in ClientResponse (mismatch of header content and property value)
- ```python-traceback
Copy-friendly signature
Failure Signature
-----------------
Documentation not mentioning treatment of invalid Content-Type headers in ClientResponse (mismatch of header content and property value)
```python-traceback
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Documentation not mentioning treatment of invalid Content-Type headers in ClientResponse (mismatch of header content and property value)
```python-traceback
Minimal Reproduction
from email.parser import HeaderParser
hp = HeaderParser()
hp.parsestr('Content-Type: jpg').get_content_type() # 'text/plain'
hp.parsestr('Content-Type: image/jpg').get_content_type() # 'image/jpg'
hp.parsestr('Content-Type: /jpg').get_content_type() # '/jpg'
Environment
- Python: 3.9.17
What Broke
Clients receive incorrect content type, causing confusion and potential processing errors.
Why It Broke
Invalid Content-Type headers lead to mismatched values in ClientResponse properties
Fix Options (Details)
Option A — Apply the official fix
Adds test coverage for invalid content type handling and documents the expected behavior, clarifying that invalid Content-Type headers default to 'text/plain'.
Fix reference: https://github.com/aio-libs/aiohttp/pull/10880
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix does not apply if the Content-Type header is valid and correctly formatted.
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
- Make timeouts explicit and test them (unit + integration) to avoid silent behavior changes.
- Instrument retries (attempt count + reason) and alert on spikes to catch dependency slowdowns.
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.