(
self,
request: Request,
call_next: Any,
)
| 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, |
nothing calls this directly
no test coverage detected