Skip to content

set charset in shareddatamiddleware #1689

@bastidest

Description

@bastidest

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'))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions