MaStr / mkPirateBox

.ipk package that turns your mint OpenWRT into a PirateBox
30 stars 2 forks source link

Mimetype support for the web server #16

Closed mathieui closed 12 years ago

mathieui commented 12 years ago

Currently, almost any uploaded file is considered 'application/octet-stream' by the web server, which prevents the browser to handle it correctly and force it to be downloaded.

The problem lies with the way the python SimpleHTTPServer handles files, by default, it serves anything as a binary blob, except for .c, .h, and .py files which are considered plain text. Theoretically, it should read the default mimetype files from the system and use that to find out the mimetype to give for an extension, but it does not seem to work.

So you just have to get a complete mimetypes file from your system (here is mine), add it to your piratebox (like in /etc/ or whatever), and fix the python code so that it reads it, by modifying the /mnt/ext/usr/lib/python2.6/SimpleHTTPServer.py file at line 202, change

        mimetypes.init()

with

        mimetypes.init(files=['/etc/mime.types'])

And it should work (also, my SimpleHTTPServer.py).

A cleaner way would be to create a class that inherits SimpleHTTPServer, but since the python on the piratebox isn’t meant to be updated or used by anything else, I am not sure it is worth the effort.

MaStr commented 12 years ago

Thank you, I'll implement it.

MaStr commented 12 years ago

Will be included in lighttpd version ;) on Stock ;P

MaStr commented 12 years ago

released