#!/usr/bin/env python3
"""Serves the attacker article on http://<host>:8080/article.html.

Binds to 0.0.0.0 so an iOS device on the same LAN can reach it; if you only
need local testing, change BIND to '127.0.0.1'.
"""
import http.server
import os
import socketserver

BIND = "0.0.0.0"
PORT = 8080
ROOT = os.path.dirname(os.path.abspath(__file__))


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

    def end_headers(self):
        # Make sure the iOS Reading List downloader always re-fetches.
        self.send_header("Cache-Control", "no-store")
        super().end_headers()


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