Skip to content

Commit 50dd4c6

Browse files
[PR #10880/3c9d7abf backport][3.12] Add invalid content type test docs (#10886)
1 parent 6473180 commit 50dd4c6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

docs/client_reference.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,12 @@ Response object
15061506

15071507
Returns value is ``'application/octet-stream'`` if no
15081508
Content-Type header present in HTTP headers according to
1509-
:rfc:`2616`. To make sure Content-Type header is not present in
1509+
:rfc:`9110`. If the *Content-Type* header is invalid (e.g., ``jpg``
1510+
instead of ``image/jpeg``), the value is ``text/plain`` by default
1511+
according to :rfc:`2045`. To see the original header check
1512+
``resp.headers['CONTENT-TYPE']``.
1513+
1514+
To make sure Content-Type header is not present in
15101515
the server reply, use :attr:`headers` or :attr:`raw_headers`, e.g.
15111516
``'CONTENT-TYPE' not in resp.headers``.
15121517

tests/test_web_response.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,13 @@ def test_ctor_content_type_with_extra() -> None:
11641164
assert resp.headers["content-type"] == "text/plain; version=0.0.4; charset=utf-8"
11651165

11661166

1167+
def test_invalid_content_type_parses_to_text_plain() -> None:
1168+
resp = Response(text="test test", content_type="jpeg")
1169+
1170+
assert resp.content_type == "text/plain"
1171+
assert resp.headers["content-type"] == "jpeg; charset=utf-8"
1172+
1173+
11671174
def test_ctor_both_content_type_param_and_header_with_text() -> None:
11681175
with pytest.raises(ValueError):
11691176
Response(

0 commit comments

Comments
 (0)