Advertisement
Guest User

Python basic HTTP server with own GET handler

a guest
Apr 22nd, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. import BaseHTTPServer
  2.  
  3. class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  4.     def do_GET(self):
  5.         if self.path.startswith('/my/'):
  6.             self.send_response(200)
  7.             self.send_header('Content-type', 'text/html')
  8.             self.end_headers()
  9.             self.wfile.write('<html><head><title>Spam</title></head><body>Eggs</body></html>')
  10.         else:
  11.             # How to use default handling here?
  12.             return
  13.  
  14. httpd = BaseHTTPServer.HTTPServer(("", 8000), MyHandler)
  15. httpd.serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement