Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SimpleHTTPServer to echo the path from GET requests
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
You can’t perform that action at this time.