MCPcopy Create free account
hub / github.com/encode/starlette / DiscardingMiddleware

Class DiscardingMiddleware

tests/middleware/test_base.py:476–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

474 test_client_factory: TestClientFactory,
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,

Calls

no outgoing calls