Skip to content

Purposefully drop connection? #2252

Closed Answered by adriangb
DanCardin asked this question in Ideas
Aug 25, 2023 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

Yes, but you'll have to do some pure ASGI stuff. We do it in some of our tests:

@pytest.mark.anyio
async def test_read_request_disconnected_client() -> None:
"""If we receive a disconnect message when the downstream ASGI
app calls receive() the Request instance passed into the dispatch function
should get marked as disconnected.
The downstream ASGI app should not get a ClientDisconnect raised,
instead if should just receive the disconnect message.
"""
async def endpoint(scope: Scope, receive: Receive, send: Send) -> None:
msg = await receive()
assert msg

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@DanCardin
Comment options

@adriangb
Comment options

@DanCardin
Comment options

Answer selected by Kludex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants