-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserve_vt_py.py
30 lines (22 loc) · 1.04 KB
/
serve_vt_py.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
30
#!/usr/bin/env python
try:
# Python 3
from http.server import HTTPServer, SimpleHTTPRequestHandler, test as test_orig
import sys
def test (*args):
test_orig(*args, port=int(sys.argv[1]) if len(sys.argv) > 1 else 8000)
except ImportError: # Python 2
from BaseHTTPServer import HTTPServer, test
from SimpleHTTPServer import SimpleHTTPRequestHandler
class CORSRequestHandler (SimpleHTTPRequestHandler):
def end_headers (self):
self.send_header('Content-Encoding', 'gzip')
self.send_header('Access-Control-Allow-Origin', '*')
SimpleHTTPRequestHandler.end_headers(self)
if __name__ == '__main__':
test(CORSRequestHandler, HTTPServer)
# Some additional context on this server / gzip compression:
# https://stackoverflow.com/questions/21956683/enable-access-control-on-simple-http-server
# https://stackoverflow.com/questions/9622998/how-to-use-content-encoding-gzip-with-python-simplehttpserver
# https://www.afternerd.com/blog/python-http-server/
# https://en.wikipedia.org/wiki/HTTP_compression