-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev_server.py
More file actions
27 lines (21 loc) · 978 Bytes
/
Copy pathdev_server.py
File metadata and controls
27 lines (21 loc) · 978 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
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
class SiteHandler(SimpleHTTPRequestHandler):
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()
def send_error(self, code, message=None, explain=None):
if code != 404:
return super().send_error(code, message, explain)
body = Path(__file__).with_name("404.html").read_bytes()
self.send_response(404)
self.send_header("Content-Type", "text/html; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
if self.command != "HEAD":
self.wfile.write(body)
if __name__ == "__main__":
print("Serving on http://localhost:8000")
ThreadingHTTPServer(("", 8000), SiteHandler).serve_forever()