Skip to content

Instantly share code, notes, and snippets.

@TheCatPlusPlus

TheCatPlusPlus/srv.py Secret

Created Oct 9, 2015
Embed
What would you like to do?
#!/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
You can’t perform that action at this time.