Skip to content

Instantly share code, notes, and snippets.

@oglops
Created October 22, 2022 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oglops/b96bd3aa9f2728d00f08a36e7a3070ef to your computer and use it in GitHub Desktop.
Save oglops/b96bd3aa9f2728d00f08a36e7a3070ef to your computer and use it in GitHub Desktop.
simple http server for testing local sphinx site
#!/usr/bin/env python3
# https://stackoverflow.com/questions/12193803/invoke-python-simplehttpserver-from-command-line-with-no-cache-option
# without this, it can not run in bg
import os
import sys
sys.stdout = open(os.devnull, 'w')
sys.stderr = open(os.devnull, 'w')
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment