Пример #1
0
 async def __call__(self, request: Request):
     sender = ASGIHTTPSender()
     await self._serve_app(
         request.scope,
         request._receive,
         sender,
     )
     return sender.build_starlette_response()
Пример #2
0
    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_starlette_response()
        return response