def request_response(self, request): """ Function to handle client requests, returning a HttpResponse object. """ # Calling middleware methods for request processing before to call the view function request._response_middleware = [] for middleware in self._middleware_instances: if hasattr(middleware, 'process_response'): request._response_middleware.insert(0, middleware.process_response) if hasattr(middleware, 'process_request'): resp = middleware.process_request(request) if resp is not None: resp.request = request return resp try: url, args, kwargs = resolve_url(request.path_info[1:], self.urls) kwargs.update(url.params) #kwargs['request'] = request # Commented to let request argument to be the first no-named arg args, kwargs = resolve_lazy_params(request, args, kwargs) args = (request,) + args resp = url.view(*args, **kwargs) if not isinstance(resp, HttpResponse): resp = HttpResponse(resp) except URLNotFound as e: raise Http404(request) # Attach the request to the response to keep it in memory, joined resp.request = request return resp
def request_handle(self, ws): """ Function to handle client requests. View must be a class """ request = WebSocketRequest(ws, service=self.name) # Calling middleware methods for request processing before to call the view function for middleware in self._middleware_instances: if hasattr(middleware, 'process_request'): resp = middleware.process_request(request) #if resp is not None: # return resp try: url, args, kwargs = resolve_url(request.path_info[1:], self.urls) kwargs.update(url.params) kwargs['request'] = request url.view(*args, **kwargs) except URLNotFound: resp = HttpResponseNotFound(request.path_info) return [resp.content]