Skip to content

Instantly share code, notes, and snippets.

@alisey
Created August 8, 2014 12:28
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 alisey/465e02517bf2076016f9 to your computer and use it in GitHub Desktop.
Save alisey/465e02517bf2076016f9 to your computer and use it in GitHub Desktop.
Quick and dirty HTTP server in Python
from http.server import HTTPServer, SimpleHTTPRequestHandler
# In Python 2 http.server is called BaseHTTPServer
class RequestHandler(SimpleHTTPRequestHandler):
def do_GET(self):
command = self.path[1:]
if command == 'wakeup':
response = 'Time to wake up!'
else:
response = 'ಠ_ಠ'
self.send_response(200)
self.send_header('Content-Type', 'text/html; charset=UTF-8')
self.send_header('Access-Control-Allow-Origin', '*')
self.end_headers()
self.wfile.write(response.encode('UTF-8'))
HTTPServer(('0.0.0.0', 8000), RequestHandler).serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment