#!/usr/bin/env python3
"""Minimal localhost HTTP server for the webshare <base href> bypass POC.

Serves poc.html and control.html on http://127.0.0.1:8080/.
http://localhost is a secure context, satisfying the [SecureContext] gate
on navigator.canShare/share.
"""
import http.server, os, socketserver, sys

PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8080
os.chdir(os.path.dirname(os.path.abspath(__file__)))

class H(http.server.SimpleHTTPRequestHandler):
    def end_headers(self):
        self.send_header('Cache-Control', 'no-store')
        super().end_headers()

socketserver.TCPServer.allow_reuse_address = True
with socketserver.TCPServer(("127.0.0.1", PORT), H) as httpd:
    print(f"serving on http://127.0.0.1:{PORT}/poc.html", flush=True)
    httpd.serve_forever()
