Skip to content

Instantly share code, notes, and snippets.

@obeattie
Created October 14, 2010 15:03
Show Gist options
  • Save obeattie/626322 to your computer and use it in GitHub Desktop.
Save obeattie/626322 to your computer and use it in GitHub Desktop.
Note this requires Python 3
#!/usr/bin/env python3
import http.server
import sys
import time
stdin = sys.stdin.detach()
class StreamingResponseRequestHandler(http.server.BaseHTTPRequestHandler):
def _stream_content(self, source):
while True:
# Totally ghetto speed limiting (76800 bytes = 600 kilobits)
chunk = source.read(76800)
if chunk:
self.wfile.write(chunk)
time.sleep(1) # EEW
else:
return
def do_GET(self):
self.send_response(200)
self.send_header('Last-Modified', self.date_time_string())
self.end_headers()
self._stream_content(stdin)
server = http.server.HTTPServer(('', 8080), StreamingResponseRequestHandler)
server.handle_request()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment