diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2018-10-22 13:14:27 +1100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-10-23 04:48:00 -0700 |
commit | 8ef7da261149ed03f25bdb5ea2611f8ce84a4d78 (patch) | |
tree | 8399dd030cf6fb172980d3b2c65bcf82d62b1168 /tools/http_server.py | |
parent | c0492ef061afd5af2044d5952432d223615841a7 (diff) |
Enforce media types
Diffstat (limited to 'tools/http_server.py')
-rwxr-xr-x | tools/http_server.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tools/http_server.py b/tools/http_server.py index c96b070e6..011f3c31a 100755 --- a/tools/http_server.py +++ b/tools/http_server.py @@ -14,9 +14,33 @@ PORT = 4545 REDIRECT_PORT = 4546 +class ContentTypeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): + def guess_type(self, path): + if ".t1." in path: + return "text/typescript" + if ".t2." in path: + return "video/vnd.dlna.mpeg-tts" + if ".t3." in path: + return "video/mp2t" + if ".j1." in path: + return "text/javascript" + if ".j2." in path: + return "application/ecmascript" + if ".j3." in path: + return "text/ecmascript" + if ".j4." in path: + return "application/x-javascript" + return SimpleHTTPServer.SimpleHTTPRequestHandler.guess_type(self, path) + + def server(): os.chdir(root_path) # Hopefully the main thread doesn't also chdir. - Handler = SimpleHTTPServer.SimpleHTTPRequestHandler + Handler = ContentTypeHandler + Handler.extensions_map.update({ + ".ts": "application/typescript", + ".js": "application/javascript", + ".json": "application/json", + }) SocketServer.TCPServer.allow_reuse_address = True s = SocketServer.TCPServer(("", PORT), Handler) print "Deno test server http://localhost:%d/" % PORT |