python basehttpserver and cgihttpserver do_GET(self), use cgi requesthandler and base requesthandler

1.1k views Asked by At
class WebServer(SocketServer.ThreadingMixIn,BaseHTTPServer.HTTPServer):

    # Works with basehttphandler
    do_get(self):
        if 'home' in self.path:
            <do something here>

# "Working" Method is commented out. The problem I'm having is being unable to
# handle requests like GET, POST, etc with CGIHTTPRequestHandler.:
#
#DoIT=BaseHTTPServer.BaseHTTPRequestHandler((SERVER_ADDRESS,PORT),WebServer)

DoIt=webserver((SERVER_ADDRESS,PORT),CGIHTTPServer.CGIHTTPRequestHandler)
DoIT.serve_forever()

This works with basehttprequesthandler, not with cgihttprequesthandler. I need a way to manage both 'types'(using both libraries?) of requests if that's even feasible. Thanks in advance.

1

There are 1 answers

0
Prashant Borde On

Try something like this:

import BaseHTTPServer
import CGIHTTPServer

server = BaseHTTPServer.HTTPServer
server_address = ("", 8888)

class MyHandler(CGIHTTPServer.CGIHTTPRequestHandler):
    def do_GET(self):
        #do something

    def do_POST(self):
        #do something

httpd = server(server_address, MyHandler)
httpd.serve_forever()