Jump to solution
Verify

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.

Jump to Verify Open PR/Commit
@@ -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
repro.py
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'
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
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
Production impact:
  • 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

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”
Issue thread · issue description · source

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
signature.txt
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.txt
Error Message ------------- Documentation not mentioning treatment of invalid Content-Type headers in ClientResponse (mismatch of header content and property value) ```python-traceback

Minimal Reproduction

repro.py
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'.

When NOT to use: This fix does not apply if the Content-Type header is valid and correctly formatted.

Fix reference: https://github.com/aio-libs/aiohttp/pull/10880

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix does not apply if the Content-Type header is valid and correctly formatted.

Verify Fix

verify
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.