Skip to content

Instantly share code, notes, and snippets.

@martianboy
Forked from dustingetz/serve.py
Last active August 29, 2015 14:01
Show Gist options
  • Save martianboy/018a2de99cf9719c679f to your computer and use it in GitHub Desktop.
Save martianboy/018a2de99cf9719c679f to your computer and use it in GitHub Desktop.
A quick http server for static files with no-cache headers that comes handy for front-end development.
#!/usr/bin/env python3
import argparse
from http.server import SimpleHTTPRequestHandler, test
class MyHTTPRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
self.send_header("Pragma", "no-cache")
self.send_header("Expires", "0")
SimpleHTTPRequestHandler.end_headers(self)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('port', action='store',
default=8000, type=int,
nargs='?',
help='Specify alternate port [default: 8000]')
args = parser.parse_args()
test(HandlerClass=MyHTTPRequestHandler, port=args.port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment