# WebRequestDispatcher

from direct.http.WebRequest import WebRequestDispatcher

Request dispatcher for HTTP requests. Contains registration and dispatching functionality.
Single-state class--multiple instances share all data. This is because we're wrapping a singleton webserver.
How to use:
w = WebRequestDispatcher() w.listenOnPort(8888) def test(replyTo,**kw): print 'test got called with these options: %s' % str(kw) replyTo.respond('<html><body>Thank you for the yummy arguments: %s' % str(kw)) w.registerGETHandler('test',test) while 1: w.poll()
Browse to http://localhost:8888/test?foo=bar and see the result!

## Inheritance:

WebRequestDispatcher: object
object:

## Methods of WebRequestDispatcher:

__init__
__new__
_favicon
_main
_services
_stylesheet
enableLandingPage
handleGET
invalidURI
listenOnPort
poll
pollHTTPTask
registerGETHandler
startCheckingIncomingHTTP
stopCheckingIncomingHTTP
unregisterGETHandler

__init__ def __init__(self, wantLandingPage=True) Undocumented function.

__new__ def __new__(self, *a, **kw) Undocumented function.

_favicon def _favicon(self, **kw) Undocumented function.

_main def _main(self) Undocumented function.

_services def _services(self) Undocumented function.

_stylesheet def _stylesheet(self, **kw) Undocumented function.

enableLandingPage def enableLandingPage(self, enable) Undocumented function.

handleGET def handleGET(self, req) Parse and dispatch a single GET request. Expects to receive a WebRequest object.

invalidURI def invalidURI(self, replyTo, **kw) Undocumented function.

listenOnPort def listenOnPort(self, listenPort) Start the web server listening if it isn't already. Singleton server, so ignore multiple listen requests.

poll def poll(self) Pump the web server, handle any incoming requests. This function should be called regularly, about 2-4 calls/sec for current applications is a good number.

pollHTTPTask def pollHTTPTask(self, task) Undocumented function.

registerGETHandler def registerGETHandler(self, uri, handler, returnsResponse=False, autoSkin=False) Call this function to register a handler function to be called in response to a query to the given URI. GET options are translated into **kw arguments. Handler function should accept **kw in order to handle arbitrary queries. If returnsResponse is False, the request is left open after handler returns--handler or tasks it creates are responsible for fulfilling the query now or in the future. Argument replyTo (a WebRequest) is guaranteed to be passed to the handler, and replyTo.respond must be called with an HTML response string to fulfill the query and close the socket. If returnsResponse is True, WebRequestDispatcher expects the handler to return its response string, and we will route the response and close the socket ourselves. No replyTo argument is provided to the handler in this case.

startCheckingIncomingHTTP def startCheckingIncomingHTTP(self, interval=0.3) Undocumented function.

stopCheckingIncomingHTTP def stopCheckingIncomingHTTP(self) Undocumented function.

unregisterGETHandler def unregisterGETHandler(self, uri) Undocumented function.