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

Serves test.pdf with Content-Type: application/pdf so Chrome routes it
to the PDF viewer (and thus into a process with ProcessLock.is_pdf()==true).
localhost is treated as a potentially-trustworthy origin, so the
FileSystemAccessManagerImpl::BindReceiver secure-context check passes.
"""
import http.server
import socketserver
import sys

PORT = 8080


class Handler(http.server.SimpleHTTPRequestHandler):
    extensions_map = {
        **http.server.SimpleHTTPRequestHandler.extensions_map,
        '.pdf': 'application/pdf',
        '.html': 'text/html',
    }

    def log_message(self, fmt, *args):  # quiet
        sys.stderr.write("[server] %s\n" % (fmt % args))


if __name__ == '__main__':
    socketserver.TCPServer.allow_reuse_address = True
    with socketserver.TCPServer(("127.0.0.1", PORT), Handler) as httpd:
        sys.stderr.write(f"[server] serving on http://127.0.0.1:{PORT}/\n")
        httpd.serve_forever()
