#!/usr/bin/env python3
"""Minimal HTTP server for the Touch-to-Fill destructor re-entrancy POC.

Serves opener.html and login.html from the current directory on port 8080.
"""
import http.server
import socketserver
import os

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):
        self.send_header('Cache-Control', 'no-store')
        super().end_headers()

    def do_POST(self):
        # Swallow the login form submit so the page doesn't 404.
        self.send_response(204)
        self.end_headers()

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