blob: 7590f9cd4cb123c2b3bee7e3cf14c96c327b61fa (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#!/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")
|