Created
September 11, 2014 18:33
-
-
Save brianz/3a43d0f6bf6e20878462 to your computer and use it in GitHub Desktop.
SimpleHTTPServer to echo the path from GET requests
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
import sys | |
import SimpleHTTPServer | |
import SocketServer | |
try: | |
PORT = int(sys.argv[1]) | |
except IndexError: | |
PORT = 8888 | |
class EchoHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | |
def do_GET(self): | |
self.send_response(200) | |
self.send_header('Content-type','text/html') | |
self.end_headers() | |
self.wfile.write('Path -> ' + self.path + '\n') | |
httpd = SocketServer.TCPServer(("", PORT), EchoHandler) | |
print "serving at port", PORT | |
try: | |
httpd.serve_forever() | |
except KeyboardInterrupt: | |
httpd.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment