def middleware(self, request: Request, handler, call_next): request.set("data", self._data, lazy=True) request.set("path", self._path, lazy=True) request.set("query_params", self._query_params, lazy=True) request.set("json", self._json, lazy=True) request.set("content_type", self._content_type, lazy=True) request.set("encoding", self._encoding, lazy=True) return call_next(request, handler)
async def middleware(self, request: Request, handler, call_next) -> Response: request.set("add_push", self._create_add_push, lazy=True) response: Response = await call_next(request, handler) if request.get(self._scope_value): response.pushes = request.get(self._scope_value) if request.get("push"): response.pushes.append( _Push(path=request.get("push").format( **request._scope).encode(), )) return response
async def middleware(self, request: Request, handler, call_next) -> Response: request.set("logger", self._logger) start = time.perf_counter() response: Response = await call_next(request, handler) self._logger.log( self.level, self.message_format, { "status": response.status, "method": request.method.decode(), "path": request.raw_path.decode(), "protocol": request.protocol.decode(), "body_size": len(response.body), "time": str(time.perf_counter() - start)[:6], "stream": request.stream, "transport": request.get_transport_info(), }, extra=self.extra, ) return response