Skip to content

Instantly share code, notes, and snippets.

@mcm
Forked from dustingetz/serve.py
Last active January 3, 2016 03:49
Show Gist options
  • Save mcm/142f39d66e87239d4b64 to your computer and use it in GitHub Desktop.
Save mcm/142f39d66e87239d4b64 to your computer and use it in GitHub Desktop.
serve static assets for frontend development, with http headers to disable caching
import argparse
from http.server import SimpleHTTPRequestHandler, test
class MyHTTPRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
super().end_headers()
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__":
parser = argparse.ArgumentParser()
parser.add_argument('--bind', '-b', default='', metavar='ADDRESS',
help='Specify alternate bind address '
'[default: all interfaces]')
parser.add_argument('port', action='store',
default=5000, type=int,
nargs='?',
help='Specify alternate port [default: 5000]')
args = parser.parse_args()
handler_class = MyHTTPRequestHandler
test(HandlerClass=handler_class, port=args.port, bind=args.bind)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment