Example #1
0
 def __call__(self, message):
     # Set script prefix from message root_path
     set_script_prefix(message.get('root_path', ''))
     signals.request_started.send(sender=self.__class__, message=message)
     # Run request through view system
     try:
         request = self.request_class(message)
     except UnicodeDecodeError:
         logger.warning('Bad Request (UnicodeDecodeError)',
                        exc_info=sys.exc_info(),
                        extra={
                            'status_code': 400,
                        })
         response = http.HttpResponseBadRequest()
     except RequestTimeout:
         # Parsing the rquest failed, so the response is a Request Timeout error
         response = HttpResponse("408 Request Timeout (upload too slow)",
                                 status_code=408)
     except RequestAborted:
         # Client closed connection on us mid request. Abort!
         return
     else:
         try:
             response = self.get_response(request)
             # Fix chunk size on file responses
             if isinstance(response, FileResponse):
                 response.block_size = 1024 * 512
         except AsgiRequest.ResponseLater:
             # The view has promised something else
             # will send a response at a later time
             return
     # Transform response into messages, which we yield back to caller
     for message in self.encode_response(response):
         # TODO: file_to_stream
         yield message
Example #2
0
 def __call__(self, message):
     # Set script prefix from message root_path
     set_script_prefix(message.get("root_path", ""))
     signals.request_started.send(sender=self.__class__, message=message)
     # Run request through view system
     try:
         request = self.request_class(message)
     except UnicodeDecodeError:
         logger.warning("Bad Request (UnicodeDecodeError)", exc_info=sys.exc_info(), extra={"status_code": 400})
         response = http.HttpResponseBadRequest()
     except RequestTimeout:
         # Parsing the rquest failed, so the response is a Request Timeout error
         response = HttpResponse("408 Request Timeout (upload too slow)", status_code=408)
     except RequestAborted:
         # Client closed connection on us mid request. Abort!
         return
     else:
         try:
             response = self.get_response(request)
             # Fix chunk size on file responses
             if isinstance(response, FileResponse):
                 response.block_size = 1024 * 512
         except AsgiRequest.ResponseLater:
             # The view has promised something else
             # will send a response at a later time
             return
     # Transform response into messages, which we yield back to caller
     for message in self.encode_response(response):
         # TODO: file_to_stream
         yield message
     # Close the response now we're done with it
     response.close()
Example #3
0
 def handle(self, body):
     """
     Synchronous message processing.
     """
     # Set script prefix from message root_path, turning None into empty string
     set_script_prefix(self.scope.get("root_path", "") or "")
     signals.request_started.send(sender=self.__class__, scope=self.scope)
     # Run request through view system
     try:
         request = self.request_class(self.scope, body)
     except UnicodeDecodeError:
         logger.warning(
             "Bad Request (UnicodeDecodeError)",
             exc_info=sys.exc_info(),
             extra={
                 "status_code": 400,
             }
         )
         response = http.HttpResponseBadRequest()
     except RequestTimeout:
         # Parsing the rquest failed, so the response is a Request Timeout error
         response = HttpResponse("408 Request Timeout (upload too slow)", status=408)
     except RequestAborted:
         # Client closed connection on us mid request. Abort!
         return
     else:
         response = self.get_response(request)
         # Fix chunk size on file responses
         if isinstance(response, FileResponse):
             response.block_size = 1024 * 512
     # Transform response into messages, which we yield back to caller
     for response_message in self.encode_response(response):
         self.send(response_message)
     # Close the response now we're done with it
     response.close()
Example #4
0
 def handle(self, body):
     """
     Synchronous message processing.
     """
     # Set script prefix from message root_path, turning None into empty string
     set_script_prefix(self.scope.get("root_path", "") or "")
     signals.request_started.send(sender=self.__class__, scope=self.scope)
     # Run request through view system
     try:
         request = self.request_class(self.scope, body)
     except UnicodeDecodeError:
         logger.warning("Bad Request (UnicodeDecodeError)",
                        exc_info=sys.exc_info(),
                        extra={
                            "status_code": 400,
                        })
         response = http.HttpResponseBadRequest()
     except RequestTimeout:
         # Parsing the rquest failed, so the response is a Request Timeout error
         response = HttpResponse("408 Request Timeout (upload too slow)",
                                 status=408)
     except RequestAborted:
         # Client closed connection on us mid request. Abort!
         return
     else:
         response = self.get_response(request)
         # Fix chunk size on file responses
         if isinstance(response, FileResponse):
             response.block_size = 1024 * 512
     # Transform response into messages, which we yield back to caller
     for response_message in self.encode_response(response):
         self.send(response_message)
     # Close the response now we're done with it
     response.close()
Example #5
0
 def __call__(self, message):
     # Set up middleware if needed. We couldn't do this earlier, because
     # settings weren't available.
     if self._request_middleware is None:
         with self.initLock:
             # Check that middleware is still uninitialized.
             if self._request_middleware is None:
                 self.load_middleware()
     # Set script prefix from message root_path
     set_script_prefix(message.get('root_path', ''))
     signals.request_started.send(sender=self.__class__, message=message)
     # Run request through view system
     try:
         request = self.request_class(message)
     except UnicodeDecodeError:
         logger.warning(
             'Bad Request (UnicodeDecodeError)',
             exc_info=sys.exc_info(),
             extra={
                 'status_code': 400,
             }
         )
         response = http.HttpResponseBadRequest()
     except RequestTimeout:
         # Parsing the rquest failed, so the response is a Request Timeout error
         response = HttpResponse("408 Request Timeout (upload too slow)", status_code=408)
     except RequestAborted:
         # Client closed connection on us mid request. Abort!
         return
     else:
         try:
             response = self.get_response(request)
             # Fix chunk size on file responses
             if isinstance(response, FileResponse):
                 response.block_size = 1024 * 512
         except AsgiRequest.ResponseLater:
             # The view has promised something else
             # will send a response at a later time
             return
     # Transform response into messages, which we yield back to caller
     for message in self.encode_response(response):
         # TODO: file_to_stream
         yield message