self.headers["location"] = quote(str(url), safe=":/%#?=@[]!$&'()*+,;")
+Content = typing.Union[str, bytes]
+SyncContentStream = typing.Iterator[Content]
+AsyncContentStream = typing.AsyncIterable[Content]
+ContentStream = typing.Union[AsyncContentStream, SyncContentStream]
+
+
class StreamingResponse(Response):
+ body_iterator: AsyncContentStream
+
def __init__(
self,
- content: typing.Any,
+ content: ContentStream,
status_code: int = 200,
headers: typing.Optional[typing.Mapping[str, str]] = None,
media_type: typing.Optional[str] = None,
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
async with anyio.create_task_group() as task_group:
- async def wrap(func: typing.Callable[[], typing.Coroutine]) -> None:
+ async def wrap(func: "typing.Callable[[], typing.Awaitable[None]]") -> None:
await func()
task_group.cancel_scope.cancel()