Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set charset in shareddatamiddleware #1689

Closed
bastidest opened this issue Dec 31, 2019 · 0 comments · Fixed by #1712
Closed

set charset in shareddatamiddleware #1689

bastidest opened this issue Dec 31, 2019 · 0 comments · Fixed by #1712
Milestone

Comments

@bastidest
Copy link

@bastidest bastidest commented Dec 31, 2019

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 (posativ/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'))
@davidism davidism added this to the 1.0.0 milestone Feb 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants