#!/usr/bin/env python3
"""
HTTP server for the RTCStatsCollectorCallbackImpl cross-thread Persistent
destruction POC. Serves poc.html and iframe.html on localhost:8080.
"""
import http.server
import socketserver
import os

PORT = 8080

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

    def end_headers(self):
        # Disable caching so iframe always refetches.
        self.send_header('Cache-Control', 'no-store')
        super().end_headers()

    def log_message(self, format, *args):
        pass  # Suppress request logging.

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.html")
    httpd.serve_forever()
