#!/usr/bin/env python3
"""Minimal HTTP server for the DevicePostureProvider cross-origin POC.

Serves files from this directory on 127.0.0.1:8080. The victim page is loaded
via http://localhost:8080/victim.html and embeds the attacker iframe via
http://127.0.0.1:8080/attacker.html so the two frames are cross-origin (and,
under default site isolation, cross-process).
"""
import http.server
import os
import socketserver

import sys
PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8765

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 log_message(self, fmt, *args):
        pass  # quiet

if __name__ == '__main__':
    socketserver.TCPServer.allow_reuse_address = True
    with socketserver.TCPServer(('127.0.0.1', PORT), Handler) as httpd:
        print(f'Serving on http://localhost:{PORT}/victim.html (and http://127.0.0.1:{PORT}/)')
        httpd.serve_forever()
