async def __call__(self, request: Request): sender = ASGIHTTPSender() await self._serve_app( request.scope, request.receive, sender, ) return sender.build_asgi_response()
async def ensure_serializable_response(self, response: Any) -> Any: if isinstance(response, starlette.responses.StreamingResponse): async def mock_receive(): # This is called in a tight loop in response() just to check # for an http disconnect. So rather than return immediately # we should suspend execution to avoid wasting CPU cycles. never_set_event = asyncio.Event() await never_set_event.wait() sender = ASGIHTTPSender() await response(scope=None, receive=mock_receive, send=sender) return sender.build_asgi_response() return response
async def __call__(self, request: starlette.requests.Request): # NOTE(simon): This is now duplicated from ASGIAppWrapper because we need to # generate FastAPI on the fly, we should find a way to unify the two. sender = ASGIHTTPSender() await self.app(request.scope, receive=request.receive, send=sender) return sender.build_asgi_response()