forked from RichardAH/browservm.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwasm.py
29 lines (23 loc) · 1.06 KB
/
wasm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Python 3
import sys
import socketserver
from http.server import SimpleHTTPRequestHandler
class WasmHandler(SimpleHTTPRequestHandler):
def end_headers(self):
# Include additional response headers here. CORS for example:
self.send_header('Cache-Control', 'no-cache')
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp');
self.send_header('Cross-Origin-Opener-Policy', 'same-origin');
self.send_header('Cross-Origin-Resource-Policy', 'cross-origin');
SimpleHTTPRequestHandler.end_headers(self)
# Python 3.7.5 adds in the WebAssembly Media Type. If this is an older
# version, add in the Media Type.
if sys.version_info < (3, 7, 5):
WasmHandler.extensions_map['.wasm'] = 'application/wasm'
if __name__ == '__main__':
PORT = 8080
HASH = "-----BEGIN RSA PRIVATE KEY-----"
with socketserver.TCPServer(("", PORT), WasmHandler) as httpd:
print("Listening on port {}. Press Ctrl+C to stop.".format(PORT))
httpd.serve_forever()