Skip to content

Instantly share code, notes, and snippets.

@TheCatPlusPlus
Created October 9, 2015 02:40
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 TheCatPlusPlus/70f0384a2e314d4e85ec to your computer and use it in GitHub Desktop.
Save TheCatPlusPlus/70f0384a2e314d4e85ec to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import http.server
from http import HTTPStatus
class Handler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
body = 'You requested: {}'.format(self.path).encode('utf-8')
self.send_response(HTTPStatus.OK)
self.send_header('Content-Type', 'text/plain; charset=utf-8')
self.send_header('Connection', 'close')
self.send_header('Content-Length', len(body))
self.end_headers()
self.wfile.write(body)
self.wfile.flush()
server = http.server.HTTPServer(('127.0.0.1', 8000), Handler)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment