Opened 6 years ago

Closed 4 years ago

#5170 defect closed duplicate (duplicate)

web.static doesn't use system MIME types

Reported by: warner Owned by:
Priority: normal Milestone:
Component: web Keywords:
Cc: jknight Branch:


When building a quick local web server with twistd web --path ., I noticed that a lot of my media files are being served as text/html instead of e.g. image/svg+xml (for .svg) and video/webm (for .webm). Investigating further, it appears that while Python's mimetypes library has a number of system files that it reads for extension-to-type mappings, twisted.web.static doesn't invoke mimetypes.init() which would allow it to read those system files. As a result, web.static sees about 130 mappings, whereas a completely init()ed mimetypes provides about 700 mappings (on my OS-X 10.6 box, using the stock python).

(I'm running Twisted 11.0.0+r32207, but current trunk appears to have the same code).

132:warner@Cookies% python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from twisted.web import static
>>> len(static.File.contentTypes)
>>> import mimetypes
>>> len(mimetypes.types_map)
>>> mimetypes.init()
>>> len(mimetypes.types_map)

My proposal is to insert a mimetypes.init() into twisted.web.static.loadMimeTypes, and to test it by first modifying mimetypes.knownfiles to include an extra file (in twisted/web/test/) that has some extra mappings, and make sure these mappings appear in the output of loadMimeTypes.

If someone tells me that I'm not missing something simple here, I'll write up the patch.

Change History (3)

comment:1 Changed 6 years ago by DefaultCC Plugin

Cc: jknight added

comment:2 Changed 6 years ago by warner

update: I'm actually using Twisted-11.0.0 (final). But again, the code in trunk looks the same.

comment:3 Changed 4 years ago by lvh

Resolution: duplicate
Status: newclosed

I've submitted #5717 for review, which fixes this ticket as a side effect (since it uses mimetypes.init). Therefore, I am closing this one as a duplicate.

Thank you for your bug report!

Note: See TracTickets for help on using tickets.