File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -1490,7 +1490,12 @@ Response object
1490
1490
1491
1491
Returns value is ``'application/octet-stream' `` if no
1492
1492
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
1494
1499
the server reply, use :attr: `headers ` or :attr: `raw_headers `, e.g.
1495
1500
``'CONTENT-TYPE' not in resp.headers ``.
1496
1501
Original file line number Diff line number Diff line change @@ -998,6 +998,13 @@ def test_ctor_content_type_with_extra() -> None:
998
998
assert resp .headers ["content-type" ] == "text/plain; version=0.0.4; charset=utf-8"
999
999
1000
1000
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
+
1001
1008
def test_ctor_both_content_type_param_and_header_with_text () -> None :
1002
1009
with pytest .raises (ValueError ):
1003
1010
web .Response (
You can’t perform that action at this time.
0 commit comments