#!/usr/bin/env python3
# Minimal HTTP server for the XML fragment-parser namespace-confusion POC.
# Serves poc.xhtml as application/xhtml+xml so Blink uses the XML parser.
import http.server
import socketserver
import sys

PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8080


class Handler(http.server.SimpleHTTPRequestHandler):
    extensions_map = {
        **http.server.SimpleHTTPRequestHandler.extensions_map,
        ".xhtml": "application/xhtml+xml",
        ".html": "text/html",
        ".js": "application/javascript",
    }

    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), Handler) as httpd:
    print(f"serving on http://127.0.0.1:{PORT}/poc.xhtml", flush=True)
    httpd.serve_forever()
