-
-
Save mcm/142f39d66e87239d4b64 to your computer and use it in GitHub Desktop.
serve static assets for frontend development, with http headers to disable caching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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