Fix Apache bug handling

This commit is contained in:
Adrián Chaves 2023-01-08 12:55:17 +01:00
parent 0d86d845e8
commit f029be3aa7
3 changed files with 7 additions and 14 deletions

View File

@ -131,7 +131,7 @@ def _get_encoding_or_mime_types_from_headers(
return encoding, None
mime_types.append(mime_type)
if b'Content-Type' in headers:
mime_types.append(headers[b'Content-Type'].split(b';')[0])
mime_types.append(headers[b'Content-Type'])
return None, mime_types

View File

@ -34,7 +34,9 @@ install_requires = [
'packaging',
'tldextract',
'lxml>=4.3.0',
'xtractmime>=0.1.0',
# TODO: Release a new version of xtractmime and use it as the minimum
# version here.
'xtractmime @ git+https://github.com/scrapy/xtractmime@c65d09c94836547dd7c6a659fe9740c112253526',
]
extras_require = {}
cpython_dependencies = [

View File

@ -33,26 +33,17 @@ PRE_XTRACTMIME_SCENARIOS = (
# affected by the Apache bug.
#
# https://mimesniff.spec.whatwg.org/#interpreting-the-resource-metadata
(
{
'body': b'\x00\x01\xff',
'headers': Headers({'Content-Type': ['text/json']}),
},
TextResponse,
),
*(
pytest.param(
(
{
'body': b'\x00\x01\xff',
'headers': Headers({'Content-Type': [content_type]}),
},
TextResponse,
marks=pytest.mark.xfail(
strict=True,
reason="https://github.com/scrapy/xtractmime/issues/13",
),
)
for content_type in (
'text/json',
# text/plain variants *not* affected by the Apache bug
'text/plain; charset=Iso-8859-1',
'text/plain; charset=utf-8',
'text/plain; charset=windows-1252',