Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions starlette/middleware/base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import typing
from contextlib import suppress

import anyio

from starlette.requests import Request
from starlette.responses import Response, StreamingResponse
from starlette.types import ASGIApp, Receive, Scope, Send
from starlette.types import ASGIApp, Message, Receive, Scope, Send

RequestResponseEndpoint = typing.Callable[[Request], typing.Awaitable[Response]]
DispatchFunction = typing.Callable[
Expand All @@ -25,9 +26,13 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
async def call_next(request: Request) -> Response:
send_stream, recv_stream = anyio.create_memory_object_stream()

async def docile_stream_send(msg: Message) -> None:
with suppress(anyio.BrokenResourceError):
await send_stream.send(msg)

async def coro() -> None:
async with send_stream:
await self.app(scope, request.receive, send_stream.send)
await self.app(scope, request.receive, docile_stream_send)

task_group.start_soon(coro)

Expand Down