HTTPServer classes

Drazen Gemic dgemic at nospam.net
Thu May 1 10:24:22 EDT 2003


Few days ago I was asking for an example of using BaseHTTPServer and 
SimpleHTTPServer, and no one seems to have one. I nthe meantime I 
managed to figure out how it works. This is the example which adds a
custom service for certain URL

import BaseHTTPServer, SimpleHTTPServer

class ReqHandler (SimpleHTTPServer.SimpleHTTPRequestHandler) :
    def do_GET(self) :
       if self.path != "/salute" :
          SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
          return
       # /service response for '/salute URL
       self.send_response(200)
       self.send_header("content-type","text/html")
       self.end_headers()
       self.wfile.write("<html><body><h1>SALUTE</h1></body></html>")


def httpLoop() :
    inst=BaseHTTPServer.HTTPServer(('',80),ReqHandler)
    inst.serve_forever()

httpLoop()







More information about the Python-list mailing list