Skip to content

Instantly share code, notes, and snippets.

@jaburns
Forked from aallan/server_notcached.py
Last active May 31, 2024 16:51
Show Gist options
  • Save jaburns/ec0f2756a4229fea639b63082fb7d44e to your computer and use it in GitHub Desktop.
Save jaburns/ec0f2756a4229fea639b63082fb7d44e to your computer and use it in GitHub Desktop.
A non-caching version of Python's SimpleHTTPServer
#!/usr/bin/env python3
import socketserver
import http.server
PORT = 8080
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")
with socketserver.TCPServer(("", PORT), MyHTTPRequestHandler) as httpd:
print("Server started at localhost:" + str(PORT))
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment