Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32041 closed Cleanup/optimization (fixed)

Document Windows caveats in mimetypes warning.

Reported by: Peter Marheine Owned by: Peter Marheine
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When using manage.py runserver for development on Windows, I've had issues with some static files being served with incorrect MIME types- particularly javascript files were being served with content type text/plain, for which most browsers will emit a warning and if the file is being loaded as a javascript module they will refuse to execute it (which is troublesome for development as you might expect).

In Django this happens in django.views.static.serve, which delegates to Python's mimetypes module to guess the MIME type of a file by name. On Windows mimetypes gets configuration from the registry, such as the key HKEY_CLASSES_ROOT\.js\Content Type (if it exists) for .js files.

Where this becomes problematic and I think it may be appropriate for Django to do something about it is that it's very easy for users to have incorrect MIME type settings in the Windows registry. I found that it was set to text/plain on this machine, which appears to have been set by either Visual Studio or VS Code and this sort of problem also seems to affect Go in the same way (https://github.com/golang/go/issues/32350) as well as being somewhat common among Django users (https://stackoverflow.com/q/16303098/2658436).

I also found (by inspecting the registry in a clean Windows sandbox) that Windows doesn't seem to ship with a MIME for .js specifically, so arguably this is just a problem with Windows in that it's easy to misconfigure. It's unclear to me what a good solution to this might look like, since if a user wanted to configure a weird MIME type for some file then the registry would be the place to do it, but Django can't tell the difference between a weird configuration that a user specifically configured and one that ended up that way accidentally. It may be most appropriate to document this particular pitfall and not make any code changes.

#6484 is a very old ticket that's related- this might be considered a point showing there is demand for packaging MIME type definitions to use on Windows.

Change History (7)

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: invalid
Status: newclosed

Django relies on mimetypes library, so that's not an issue (if any) in Django but in Python. We shouldn't add any workarounds in Django. Please report it in https://bugs.python.org. You can find several related reports in Python's bugs tracker, e.g. issue10551, so probably it's already reported.

comment:2 by Peter Marheine, 4 years ago

Resolution: invalid
Status: closednew
Version: 3.1master

From some discussion on django-developers, I'm reopening this; though a code change doesn't seem warranted, the staticfiles documentation can be updated to mention the Windows pitfalls as it already does for some Linux distributions.

comment:3 by Peter Marheine, 4 years ago

Owner: changed from nobody to Peter Marheine
Status: newassigned

comment:4 by Mariusz Felisiak, 4 years ago

Component: Core (Management commands)Documentation
Summary: Detected MIME types can easily be wrong on WindowsDocument Windows caveats in mimetypes warning.
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:5 by Mariusz Felisiak, 4 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In f87b0ec:

Fixed #32041 -- Doc'd how to modify served files' content types on Windows.

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 1c7799db:

[3.1.x] Fixed #32041 -- Doc'd how to modify served files' content types on Windows.

Backport of f87b0ecd37e64e7a019d472de37d0789a8790f1f from master

Note: See TracTickets for help on using tickets.
Back to Top