Commit 077153e9 authored by Guido van Rossum's avatar Guido van Rossum

- Use mimetypes.types_map to initialize extensions_map.

- Change the default file type to application/octet-stream.
- Add support to recognize .py, .c, .h files as text/plain (this is
  what I use most :-).
parent 2d3eb133
...@@ -6,7 +6,7 @@ and HEAD requests in a fairly straightforward manner. ...@@ -6,7 +6,7 @@ and HEAD requests in a fairly straightforward manner.
""" """
__version__ = "0.5" __version__ = "0.6"
import os import os
...@@ -16,6 +16,7 @@ import BaseHTTPServer ...@@ -16,6 +16,7 @@ import BaseHTTPServer
import urllib import urllib
import cgi import cgi
import shutil import shutil
import mimetypes
from StringIO import StringIO from StringIO import StringIO
...@@ -179,14 +180,13 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): ...@@ -179,14 +180,13 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
else: else:
return self.extensions_map[''] return self.extensions_map['']
extensions_map = { extensions_map = mimetypes.types_map.copy()
'': 'text/plain', # Default, *must* be present extensions_map.update({
'.html': 'text/html', '': 'application/octet-stream', # Default
'.htm': 'text/html', '.py': 'text/plain',
'.gif': 'image/gif', '.c': 'text/plain',
'.jpg': 'image/jpeg', '.h': 'text/plain',
'.jpeg': 'image/jpeg', })
}
def test(HandlerClass = SimpleHTTPRequestHandler, def test(HandlerClass = SimpleHTTPRequestHandler,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment