#!/usr/bin/env python import http.server import os class NoCacheHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): def end_headers(self): self.send_header('Cache-Control', 'no-cache, no-store, must-revalidate') # HTTP 1.1 self.send_header('Pragma', 'no-cache') # HTTP 1.0 self.send_header('Expires', '0') # Proxies super().end_headers() def run(server_class=http.server.HTTPServer, port=8080, directory="./result"): # Set the directory for the handler handler_class = NoCacheHTTPRequestHandler handler_class.directory = os.path.abspath(directory) # Change the current working directory to the specified directory os.chdir(os.path.abspath(directory)) # Create the server on 127.0.0.1 with server_class(("127.0.0.1", port), handler_class) as httpd: print( f"Serving on http://127.0.0.1:{port} from directory '{handler_class.directory}'" ) httpd.serve_forever() if __name__ == "__main__": run(port=8080, directory="./result")