2022-04-05 11:21:11 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import argparse
|
|
|
|
from http import server
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Start a local webserver with a Python terminal."
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--port", type=int, default=8000, help="port for the http server to listen on"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--bind", type=str, default="127.0.0.1", help="Bind address (empty for all)"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class MyHTTPRequestHandler(server.SimpleHTTPRequestHandler):
|
2022-04-10 09:29:51 +02:00
|
|
|
extensions_map = server.SimpleHTTPRequestHandler.extensions_map.copy()
|
|
|
|
extensions_map.update(
|
|
|
|
{
|
|
|
|
".wasm": "application/wasm",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-09-19 07:49:26 +02:00
|
|
|
def end_headers(self) -> None:
|
2022-04-05 11:21:11 +02:00
|
|
|
self.send_my_headers()
|
|
|
|
super().end_headers()
|
|
|
|
|
2023-09-19 07:49:26 +02:00
|
|
|
def send_my_headers(self) -> None:
|
2022-04-05 11:21:11 +02:00
|
|
|
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
|
|
|
|
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
|
|
|
|
|
|
|
|
|
2023-09-19 07:49:26 +02:00
|
|
|
def main() -> None:
|
2022-04-05 11:21:11 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
if not args.bind:
|
|
|
|
args.bind = None
|
|
|
|
|
2023-09-19 07:49:26 +02:00
|
|
|
server.test( # type: ignore[attr-defined]
|
2022-04-05 11:21:11 +02:00
|
|
|
HandlerClass=MyHTTPRequestHandler,
|
|
|
|
protocol="HTTP/1.1",
|
|
|
|
port=args.port,
|
|
|
|
bind=args.bind,
|
|
|
|
)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|