fix: Override server JS MIME type if text/plain

On systems such as Windows, JavaScript files can be incorrectly assigned
the "text/plain" MIME type in Python's mimetypes module. This overrides
this behavior when it occurs.
This commit is contained in:
Justin Mayer 2026-04-19 10:28:52 +02:00
commit 27b25bc05f

View file

@ -120,6 +120,11 @@ class ComplexHTTPRequestHandler(server.SimpleHTTPRequestHandler):
if mimetype == "application/octet-stream" and magic_from_file:
mimetype = magic_from_file(path, mime=True)
# On some systems, JavaScript files are incorrectly assigned the "text/plain"
# MIME type in Python's mimetypes module. Override this behavior when it occurs.
if posixpath.splitext(path)[1] == ".js" and mimetype == "text/plain":
mimetype = "text/javascript"
return mimetype
def log_message(self, msg_format, *args):