simple_http_server.py 756 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python
  2. import SimpleHTTPServer
  3. import SocketServer
  4. import cgi
  5. import sys
  6. PORT = 8080
  7. # Simple server to respond to both POST and GET requests. POST requests will
  8. # just respond as normal GETs.
  9. class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
  10. def do_GET(self):
  11. SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
  12. def do_POST(self):
  13. SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
  14. Handler = ServerHandler
  15. # Allows use to restart server immediately after restarting it.
  16. SocketServer.ThreadingTCPServer.allow_reuse_address = True
  17. httpd = SocketServer.TCPServer(("", PORT), Handler)
  18. print ("Serving at: http://%s:%s" % ("localhost", PORT))
  19. httpd.serve_forever()