def __call__(self, environ, start_response): '''Handle WSGI request''' req=Request(self, environ['REMOTE_ADDR'], environ['HTTP_HOST']) method=environ['REQUEST_METHOD'] if method=='GET': return self.do_GET(req, environ, start_response) elif method=='POST': return self.do_POST(req, environ, start_response) else: start_response("400 Bad request", []) return []
class HTTPRequestHandler(BaseHTTPRequestHandler): '''JSON-RPC request handler for HTTP''' _CookieNamePrefix='qxjsonrpc_' _DefaultCookieName='session_id' def __init__(self, request, client_address, server): '''Initialize request handlers''' self.req=Request(server, client_address, server.domain) BaseHTTPRequestHandler.__init__(self, request, client_address, server) def do_GET(self): '''Handle GET request. Can handle normal GET requests and the ScriptTransport protocol.''' try: # Determine request domain self.req.domain=self.headers.get('host', None) # Load session if applicable self.loadSession() loadedSession=self.req.session # Parse URL url=urlparse.urlparse(self.path) query=cgi.parse_qs(url[4], True) for k in query: query[k]=query[k][0] # Expand ScriptTransport arguments if any scriptTransportID=query.pop('_ScriptTransport_id', None) scriptTransportData=query.pop('_ScriptTransport_data', None) # Determine transport type if scriptTransportID and scriptTransportData: # ScriptTransport, JSON encoded request object is in _ScriptTransport_data if self.debug: self.logger.info('Transport: HTTP GET - ScriptTransport') self.req.loadJSON(scriptTransportData) response=self.req.process() # Encode qooxdoo specific ScriptTransport response response='qx.io.remote.ScriptTransport._requestFinished(%s,%s);'%(scriptTransportID,response) else: # Request is defined as queryvariables, params and server_data are JSON encoded if self.debug: self.logger.info('Transport: HTTP GET - Query variables') self.req.load(('id','params','server_data'), **query) response=self.req.process() # Send response to the client self.sendResponse(response, loadedSession) except ServerError,e: self.send_error(400, '[%s]: %s'%(e.__class__.__name__, e)) except Exception,e: self.send_error(500, 'Internal server error') raise
def __init__(self, request, client_address, server): '''Initialize request handlers''' self.req=Request(server, client_address, server.domain) BaseHTTPRequestHandler.__init__(self, request, client_address, server)