Description
UTF-8 Javascript files served by the SharedDataMiddleware do not contain a charset in the Content-Type response header. This leads to issues of javascript interpreted as US-ASCII by browsers (isso-comments/isso#607).
Current
Content-Type: application/javascript
Expected
Content-Type: application/javascript; charset=UTF-8
The mime type is deducted by using python's mimetypes module and the filename:
|
guessed_type = mimetypes.guess_type(real_filename) |
|
mime_type = guessed_type[0] or self.fallback_mimetype |
It is sent without appending an encoding:
|
("Content-Type", mime_type), |
Other usages seem to suggest that a call to get_content_type is necessary to append the charset, if applicable:
|
self.headers["Content-Type"] = get_content_type(value, self.charset) |
Possible solutions
I am not familiar with the codebase, but would it be possible to call get_content_type? I tried to modify it myself, but I don't know where to get the encoding from inside SharedDataMiddleware.
My problem is solved when I hardcode 'utf-8' as charset:
("Content-Type", get_content_type(mime_type, 'utf-8'))
Description
UTF-8 Javascript files served by the SharedDataMiddleware do not contain a charset in the
Content-Typeresponse header. This leads to issues of javascript interpreted as US-ASCII by browsers (isso-comments/isso#607).Current
Expected
The mime type is deducted by using python's mimetypes module and the filename:
werkzeug/src/werkzeug/middleware/shared_data.py
Lines 256 to 257 in aa9676f
It is sent without appending an encoding:
werkzeug/src/werkzeug/middleware/shared_data.py
Line 281 in aa9676f
Other usages seem to suggest that a call to
get_content_typeis necessary to append the charset, if applicable:werkzeug/src/werkzeug/wrappers/common_descriptors.py
Line 146 in e76aac8
Possible solutions
I am not familiar with the codebase, but would it be possible to call
get_content_type? I tried to modify it myself, but I don't know where to get the encoding from insideSharedDataMiddleware.My problem is solved when I hardcode 'utf-8' as charset: