#!/usr/bin/env python3
"""Minimal static-file server for the CroppingWindowCapturer TOCTOU POC.

Serves poc.html / popup.html on http://localhost:8080/.
getDisplayMedia is available on http://localhost without TLS.
"""
import http.server
import os
import socketserver

PORT = 8080


class Handler(http.server.SimpleHTTPRequestHandler):
    def __init__(self, *a, **kw):
        super().__init__(*a, directory=os.path.dirname(os.path.abspath(__file__)), **kw)

    def end_headers(self):
        # Allow window.open + cross-window scripting of the popup we serve.
        self.send_header("Cache-Control", "no-store")
        super().end_headers()


if __name__ == "__main__":
    socketserver.TCPServer.allow_reuse_address = True
    with socketserver.TCPServer(("127.0.0.1", PORT), Handler) as httpd:
        print(f"serving on http://localhost:{PORT}/poc.html")
        httpd.serve_forever()
