Closed moreymat closed 4 years ago
I initially wanted to base this PR on develop
but develop
is currently 7 commits behind master
.
I'm worried that this will break if there is ever a response without a Content-Type
header (i.e. where it's None
). Regarding the parsing of the headers with extra params, that's also implemented in pantomime
and might be better to use from there:
from pantomime import normalize_mimetype
mime_type = normalize_mimetype(headers.get('Content-Type'))
i.e.:
out = normalize_mimetype('text/html; encoding=utf-8')
assert out == 'text/html'
@pudo good point, should be fixed now :-)
This PR extracts the MIME type from the (possibly longer) Content-Type. Extra elements (eg. charset) cause
mimetypes.guess_extension()
to returnNone
, so we drop them.