-
-
Save scottj/a510d6bd96941901fb99554566ee226d to your computer and use it in GitHub Desktop.
A simple Python HTTP server that can handle mime types properly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import http.server | |
import socketserver | |
HOST = "localhost" | |
PORT = 8000 | |
class HttpRequestHandler(http.server.SimpleHTTPRequestHandler): | |
extensions_map = {".manifest": "text/cache-manifest"} | |
def version_string(self): | |
return "Apache/1.3.0 (Win32)" | |
try: | |
with socketserver.TCPServer((HOST, PORT), HttpRequestHandler) as httpd: | |
print(f"serving at http://{HOST}:{PORT}") | |
httpd.serve_forever() | |
except KeyboardInterrupt: | |
pass |
Since Python 3.9, the extensions_map
parameter is used solely to override a vast list of default values with custom MIME types, mostly rendering this script superfluous. Redundant MIME types have been removed.
Additionally, I added an override for the Server
header in this version.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated with suggestion from @jan25 here.