#!/usr/bin/env python3
"""Serves the POC web content (poc.html, manifest.json, icons) on port 8080.

Note: for the *MAC-bearing* addWebapp() path, Chrome requires an installable
manifest, which in practice means HTTPS. For local testing you can either:
  * front this with `adb reverse tcp:8080 tcp:8080` and launch Chrome with
    --unsafely-treat-insecure-origin-as-secure=http://localhost:8080
    (environment-only flag; does not affect the bug-triggering logic), or
  * deploy web/ to any HTTPS host you control.
"""
import http.server
import os
import socketserver

PORT = 8080
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "web")


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

    def end_headers(self):
        self.send_header("Cache-Control", "no-store")
        super().end_headers()


if __name__ == "__main__":
    print(f"Serving {ROOT} on http://0.0.0.0:{PORT}/poc.html")
    with socketserver.TCPServer(("0.0.0.0", PORT), Handler) as httpd:
        httpd.serve_forever()
