Created
August 8, 2014 12:28
-
-
Save alisey/465e02517bf2076016f9 to your computer and use it in GitHub Desktop.
Quick and dirty HTTP server in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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