-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-server.py.txt
More file actions
36 lines (24 loc) · 1.05 KB
/
Copy pathsimple-server.py.txt
File metadata and controls
36 lines (24 loc) · 1.05 KB
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
30
31
32
33
34
35
36
#!/usr/bin/env python3
# Adapted from
# https://stackoverflow.com/questions/21956683/enable-access-control-on-simple-http-server
# https://dzone.com/articles/extending-pythons-simple-http-server
import sys
if sys.version_info < (3, 0, 0):
print("Requires Python3!")
sys.exit(0)
from http.server import HTTPServer, SimpleHTTPRequestHandler, test as test_orig
import socketserver
def test(*args):
prt = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
test_orig(*args, port=prt, bind="localhost")
class CustomRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
self.send_header("Cross-Origin-Opener-Policy", "same-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):
CustomRequestHandler.extensions_map[".wasm"] = "application/wasm"
if __name__ == "__main__":
test(CustomRequestHandler, HTTPServer)