Skip to content

Commit 76a3812

Browse files
ninosekiKludex
andauthored
Revert raise ClientDisconnected on HTTP (#2276) (#2276)
* chore: revert #2220 * Don't revert the receive changes --------- Co-authored-by: Marcelo Trylesinski <[email protected]>
1 parent a05ae64 commit 76a3812

File tree

3 files changed

+3
-34
lines changed

3 files changed

+3
-34
lines changed

tests/protocols/test_http.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from uvicorn.lifespan.on import LifespanOn
1717
from uvicorn.main import ServerState
1818
from uvicorn.protocols.http.h11_impl import H11Protocol
19-
from uvicorn.protocols.utils import ClientDisconnected
2019

2120
try:
2221
from uvicorn.protocols.http.httptools_impl import HttpToolsProtocol
@@ -587,25 +586,6 @@ async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable
587586
assert got_disconnect_event
588587

589588

590-
@pytest.mark.anyio
591-
async def test_disconnect_on_send(http_protocol_cls: HTTPProtocol) -> None:
592-
got_disconnected = False
593-
594-
async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):
595-
try:
596-
await send({"type": "http.response.start", "status": 200})
597-
except ClientDisconnected:
598-
nonlocal got_disconnected
599-
got_disconnected = True
600-
601-
protocol = get_connected_protocol(app, http_protocol_cls)
602-
protocol.data_received(SIMPLE_GET_REQUEST)
603-
protocol.eof_received()
604-
protocol.connection_lost(None)
605-
await protocol.loop.run_one()
606-
assert got_disconnected
607-
608-
609589
@pytest.mark.anyio
610590
async def test_early_response(http_protocol_cls: HTTPProtocol):
611591
app = Response("Hello, world", media_type="text/plain")

uvicorn/protocols/http/h11_impl.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
service_unavailable,
2828
)
2929
from uvicorn.protocols.utils import (
30-
ClientDisconnected,
3130
get_client_addr,
3231
get_local_addr,
3332
get_path_with_query_string,
@@ -408,8 +407,6 @@ async def run_asgi(self, app: ASGI3Application) -> None:
408407
result = await app( # type: ignore[func-returns-value]
409408
self.scope, self.receive, self.send
410409
)
411-
except ClientDisconnected:
412-
pass
413410
except BaseException as exc:
414411
msg = "Exception in ASGI application\n"
415412
self.logger.error(msg, exc_info=exc)
@@ -458,7 +455,7 @@ async def send(self, message: ASGISendEvent) -> None:
458455
await self.flow.drain()
459456

460457
if self.disconnected:
461-
raise ClientDisconnected
458+
return
462459

463460
if not self.response_started:
464461
# Sending response status line and headers

uvicorn/protocols/http/httptools_impl.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
service_unavailable,
3030
)
3131
from uvicorn.protocols.utils import (
32-
ClientDisconnected,
3332
get_client_addr,
3433
get_local_addr,
3534
get_path_with_query_string,
@@ -412,8 +411,6 @@ async def run_asgi(self, app: ASGI3Application) -> None:
412411
result = await app( # type: ignore[func-returns-value]
413412
self.scope, self.receive, self.send
414413
)
415-
except ClientDisconnected:
416-
pass
417414
except BaseException as exc:
418415
msg = "Exception in ASGI application\n"
419416
self.logger.error(msg, exc_info=exc)
@@ -462,7 +459,7 @@ async def send(self, message: ASGISendEvent) -> None:
462459
await self.flow.drain()
463460

464461
if self.disconnected:
465-
raise ClientDisconnected
462+
return
466463

467464
if not self.response_started:
468465
# Sending response status line and headers
@@ -573,11 +570,6 @@ async def receive(self) -> ASGIReceiveEvent:
573570

574571
if self.disconnected or self.response_complete:
575572
return {"type": "http.disconnect"}
576-
577-
message: HTTPRequestEvent = {
578-
"type": "http.request",
579-
"body": self.body,
580-
"more_body": self.more_body,
581-
}
573+
message: HTTPRequestEvent = {"type": "http.request", "body": self.body, "more_body": self.more_body}
582574
self.body = b""
583575
return message

0 commit comments

Comments
 (0)