Skip to content

Commit

Permalink
Work around Windows 10 mime type bug for javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas FitzRoy-Dale committed Aug 5, 2024
1 parent f0fea1f commit d04c6b3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion rime/rimeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ async def run_cmd_in_background_rime():
return result


STATIC_MIME_TYPES = {
'.js': 'application/javascript',
}


class ZippedStaticFiles:
def __init__(self, zip_pathname):
self.zf = zipfile.ZipFile(zip_pathname, 'r')
Expand All @@ -81,7 +86,14 @@ def __call__(self, path):
if path == '':
path = 'index.html'

mime_type = mimetypes.guess_type(path)[0]
# Windows 10 (may?) incorrectly identify JavaScript as text/plain. See https://bugs.python.org/issue43975
for ext, candidate_mime_type in STATIC_MIME_TYPES.items():
if path.endswith(ext):
mime_type = candidate_mime_type
break
else:
mime_type = mimetypes.guess_type(path)[0]

return StreamingResponse(self.zf.open(path), media_type=mime_type)


Expand Down

0 comments on commit d04c6b3

Please sign in to comment.