#!/usr/bin/env python3
"""Minimal HTTP server for the POC.

Serves victim.html on port 9080 and attacker.html on port 9081. Chrome is
launched with --host-resolver-rules mapping victim.test and attacker.test to
127.0.0.1, so the two pages are cross-SITE (different eTLD+1) and run in
separate renderer processes under Site Isolation. This demonstrates that the
leaked PDF crosses a site boundary.
"""
import http.server
import os
import socketserver
import threading

ROOT = os.path.dirname(os.path.abspath(__file__))


class Handler(http.server.SimpleHTTPRequestHandler):
    def __init__(self, *a, **kw):
        super().__init__(*a, directory=ROOT, **kw)

    def log_message(self, fmt, *a):
        pass  # quiet


def serve(port):
    socketserver.TCPServer.allow_reuse_address = True
    with socketserver.TCPServer(("127.0.0.1", port), Handler) as httpd:
        httpd.serve_forever()


if __name__ == "__main__":
    threading.Thread(target=serve, args=(9081,), daemon=True).start()
    print("serving victim on http://victim.test:9080/victim.html")
    print("serving attacker on http://attacker.test:9081/attacker.html")
    serve(9080)
