Files
homelab-docs/homelab/vpn-route-check/serve_no_cache.py
2026-02-23 16:47:17 +03:00

23 lines
796 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Минимальный HTTP-сервер для /data с заголовками no-cache, чтобы браузер не кэшировал страницу."""
import http.server
import os
DIR = os.environ.get("SERVE_DIR", "/data")
PORT = int(os.environ.get("SERVE_PORT", "8765"))
class NoCacheHandler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=DIR, **kwargs)
def end_headers(self):
self.send_header("Cache-Control", "no-store, no-cache, must-revalidate")
self.send_header("Pragma", "no-cache")
self.send_header("Expires", "0")
super().end_headers()
if __name__ == "__main__":
http.server.HTTPServer(("", PORT), NoCacheHandler).serve_forever()