-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.py
66 lines (43 loc) · 1.76 KB
/
serve.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# Inspired by https://stackoverflow.com/a/25708957/51280
from http.server import SimpleHTTPRequestHandler
import socketserver
import requests
class MyHTTPRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
self.send_header("Pragma", "no-cache")
self.send_header("Expires", "0")
if __name__ == '__main__':
with socketserver.TCPServer(("", 8001), MyHTTPRequestHandler) as httpd:
print("serving at port", 8001)
httpd.serve_forever()
#!/usr/bin/env python3
# import http.server
# class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
# def end_headers(self):
# self.send_my_headers()
# http.server.SimpleHTTPRequestHandler.end_headers(self)
# def send_my_headers(self):
# self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
# self.send_header("Pragma", "no-cache")
# self.send_header("Expires", "0")
# if __name__ == '__main__':
# http.server.test(HandlerClass=MyHTTPRequestHandler, port=8001)
# import http.server
# PORT = 8001
# class NoCacheHTTPRequestHandler(
# http.server.SimpleHTTPRequestHandler
# ):
# def send_response_only(self, code, message=None):
# super().send_response_only(code, message)
# self.send_header('Cache-Control', 'no-store, must-revalidate')
# self.send_header('Expires', '0')
# if __name__ == '__main__':
# http.server.test(
# HandlerClass=NoCacheHTTPRequestHandler,
# port=PORT
# )