def handle(self): self.timeout = Timeout(120, Exception) self.timeout.start() try: WSGIHandler.handle(self) except Timeout as ex: if ex is self.timeout: pass else: raise
def handle_one_response(self): try: return WSGIHandler.handle_one_response(self) finally: self.close_connection = True self.close_task.kill() self.close_task = None
self.start_response('400 Bad Request', [('Connection', 'close')]) self.write('') if self.websocket is not None: self.websocket.detach() self.websocket = None except: if self.websocket is not None: self.websocket.close() raise finally: if self.websocket is not None: self.socket = None self.websocket = None self.environ.pop('wsgi.get_websocket', None) else: return WSGIHandler.run_application(self) def read_requestline(self): data = self.rfile.read(7) if data[:1] == '<': try: data += self.rfile.read(15) if data.lower() == '<policy-file-request/>': self.socket.sendall(self.server.flash_policy) else: self.log_error('Invalid request: %r', data) finally: self.socket.shutdown(SHUT_WR) self.socket.close() self.socket = None else:
def __init__(self, sock, address, server, rfile=None): if server.address_family == socket.AF_UNIX: address = ['0.0.0.0'] WSGIHandler.__init__(self, sock, address, server, rfile)
def __init__(self, *args, **kwargs): WSGIHandler.__init__(self, *args, **kwargs) self.client_address = ('ipc', 0)
def get_environ(self): environ = _WSGIHandler.get_environ(self) environ['RAW_URI'] = self.path return environ
def wsgi_handler(stream): socket = FakeSocket(stream) address = socket.getpeername() handler = WSGIHandler(socket, address, FakeServer(application)) handler.handle()
def __init__(self, *args, **kwargs): self.status=None WSGIHandler.__init__(self, *args, **kwargs)
def handle_one_response(self): self.status = None self.headers_sent = False self.result = None self.response_length = 0 self.response_use_chunked = False path = self.environ.get('PATH_INFO') logger.info("REQUEST: %s @ %s", self.environ["SERVER_PORT"], path) request_method = self.environ.get("REQUEST_METHOD") request_tokens = self.RE_REQUEST_URL.match(path) # Kick non-socket.io requests to our superclass if not path.lstrip('/').startswith(self.server.namespace): return WSGIHandler.handle_one_response(self) # Parse request URL and QUERY_STRING and do handshake if request_tokens: request_tokens = request_tokens.groupdict() else: handshake_tokens = self.RE_HANDSHAKE_URL.match(path) if handshake_tokens: return self._do_handshake(handshake_tokens.groupdict()) else: # This is no socket.io request. Let the WSGI app handle it. return WSGIHandler.handle_one_response(self) # Setup the transport and session transport = self.handler_types.get(request_tokens["transport_id"]) session_id = request_tokens["session_id"] session = self.server.get_session(session_id) if session is None: logger.warning("Connection from dead session: %s", session_id) headers = [("Content-Type", "text/plain")] if self.server.cors_domain: headers += [ ("Access-Control-Allow-Origin", self.server.cors_domain), ("Access-Control-Allow-Credentials", "true"), ] self.start_response("404 Session not found", headers) self.result = [""] self.process_result() return logger.debug("Connection for session %r, transport %r", session.session_id, transport) # Make the session object available for WSGI apps self.environ['socketio'] = protocol.PySocketProtocol(session) if transport is transports.WebsocketTransport: # fake application try: _tmp, self.application = self.application, lambda *args: None logger.debug("Initializing websocket.") WebSocketHandler.handle_one_response(self) finally: self.application = _tmp # Create a transport and handle the request likewise logger.debug("Connecting transport: %r", transport) transport(self).connect(session, request_method) if session.wsgi_app_greenlet is not None: if not session.wsgi_app_greenlet: logger.debug("Joining finalized greenlet %r -> %r", self, session.wsgi_app_greenlet) session.wsgi_app_greenlet.join() session.wsgi_app_greenlet = None if not session.wsgi_app_greenlet: start_response = lambda status, headers, exc = None: None logger.debug("Spawning new greenlet for session: %r", session) session_greenlet = SessionGreenlet.spawn(self.application, self.environ, start_response) session_greenlet.join() logger.debug("Session greenlet joined: %r", session) del session
def log_request(self): logger.info(WSGIHandler.format_request(self))
def log_request(self): WSGIHandler.log_request(self)
def log_request(self): if isinstance(self.code, (int, long)) and 400 <= self.code <= 599: WSGIHandler.log_request(self)