Skip to content

Commit 3c9d7ab

Browse files
hanlee55bdracoDreamsorcerer
authored
Add invalid content type test docs (#10880)
Co-authored-by: J. Nick Koston <[email protected]> Co-authored-by: Sam Bull <[email protected]>
1 parent 4facc40 commit 3c9d7ab

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
@@ -1490,7 +1490,12 @@ Response object
14901490

14911491
Returns value is ``'application/octet-stream'`` if no
14921492
Content-Type header present in HTTP headers according to
1493-
:rfc:`2616`. To make sure Content-Type header is not present in
1493+
:rfc:`9110`. If the *Content-Type* header is invalid (e.g., ``jpg``
1494+
instead of ``image/jpeg``), the value is ``text/plain`` by default
1495+
according to :rfc:`2045`. To see the original header check
1496+
``resp.headers['CONTENT-TYPE']``.
1497+
1498+
To make sure Content-Type header is not present in
14941499
the server reply, use :attr:`headers` or :attr:`raw_headers`, e.g.
14951500
``'CONTENT-TYPE' not in resp.headers``.
14961501

tests/test_web_response.py

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

10001000

1001+
def test_invalid_content_type_parses_to_text_plain() -> None:
1002+
resp = web.Response(text="test test", content_type="jpeg")
1003+
1004+
assert resp.content_type == "text/plain"
1005+
assert resp.headers["content-type"] == "jpeg; charset=utf-8"
1006+
1007+
10011008
def test_ctor_both_content_type_param_and_header_with_text() -> None:
10021009
with pytest.raises(ValueError):
10031010
web.Response(

0 commit comments

Comments
 (0)