37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
#!/usr/bin/env python
|
|
import argparse
|
|
import os
|
|
from functools import partial
|
|
|
|
try:
|
|
from http import server # Python 3
|
|
except ImportError:
|
|
import SimpleHTTPServer as server # Python 2
|
|
|
|
class MyHTTPRequestHandler(server.SimpleHTTPRequestHandler):
|
|
def end_headers(self):
|
|
self.send_my_headers()
|
|
server.SimpleHTTPRequestHandler.end_headers(self)
|
|
|
|
def send_my_headers(self):
|
|
self.send_header("Access-Control-Allow-Origin", "*")
|
|
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
|
|
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
|
|
|
|
if __name__ == '__main__':
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--bind', '-b', metavar='ADDRESS',
|
|
help='Specify alternate bind address '
|
|
'[default: all interfaces]')
|
|
parser.add_argument('--directory', '-d', default=os.getcwd(),
|
|
help='Specify alternative directory '
|
|
'[default:current directory]')
|
|
parser.add_argument('port', action='store',
|
|
default=8000, type=int,
|
|
nargs='?',
|
|
help='Specify alternate port [default: 8000]')
|
|
args = parser.parse_args()
|
|
server.test(HandlerClass=partial(MyHTTPRequestHandler, directory=args.directory), port=args.port, bind=args.bind)
|