-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
executable file
·29 lines (25 loc) · 977 Bytes
/
server.py
File metadata and controls
executable file
·29 lines (25 loc) · 977 Bytes
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
#!/usr/bin/env python3
from http.server import HTTPServer, SimpleHTTPRequestHandler
import os
class CustomHandler(SimpleHTTPRequestHandler):
def end_headers(self):
# Disable caching
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
self.send_header('Pragma', 'no-cache')
self.send_header('Expires', '0')
super().end_headers()
def send_error(self, code, message=None, explain=None):
if code == 404:
# Redirect to custom 404 handler
self.path = '/404.html'
return self.do_GET()
return super().send_error(code, message, explain)
if __name__ == '__main__':
os.chdir('.') # Serve from current dir
httpd = HTTPServer(('0.0.0.0', 8080), CustomHandler)
print("Serving on http://localhost:8080")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nShutting down server.")
httpd.server_close()