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 @@ -1506,7 +1506,12 @@ Response object
1506
1506
1507
1507
Returns value is ``'application/octet-stream' `` if no
1508
1508
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
1510
1515
the server reply, use :attr: `headers ` or :attr: `raw_headers `, e.g.
1511
1516
``'CONTENT-TYPE' not in resp.headers ``.
1512
1517
Original file line number Diff line number Diff line change @@ -1164,6 +1164,13 @@ def test_ctor_content_type_with_extra() -> None:
1164
1164
assert resp .headers ["content-type" ] == "text/plain; version=0.0.4; charset=utf-8"
1165
1165
1166
1166
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
+
1167
1174
def test_ctor_both_content_type_param_and_header_with_text () -> None :
1168
1175
with pytest .raises (ValueError ):
1169
1176
Response (
You can’t perform that action at this time.
0 commit comments