MCPcopy
hub / github.com/encode/starlette / dispatch

Method dispatch

tests/middleware/test_base.py:477–494  ·  view source on GitHub ↗
(
            self,
            request: Request,
            call_next: Any,
        )

Source from the content-addressed store, hash-verified

475) -> None:
476 class DiscardingMiddleware(BaseHTTPMiddleware):
477 async def dispatch(
478 self,
479 request: Request,
480 call_next: Any,
481 ) -> PlainTextResponse:
482 # As a matter of ordering, this test targets the case where the downstream
483 # app response is discarded while it is sending a response body.
484 # We need to wait for the downstream app to begin sending a response body
485 # before sending the middleware response that will overwrite the downstream
486 # response.
487 downstream_app_response = await call_next(request)
488 body_generator = downstream_app_response.body_iterator
489 try:
490 await body_generator.__anext__()
491 finally:
492 await body_generator.aclose()
493
494 return PlainTextResponse("Custom")
495
496 async def downstream_app(
497 scope: Scope,

Callers

nothing calls this directly

Calls 2

PlainTextResponseClass · 0.90
__anext__Method · 0.80

Tested by

no test coverage detected