Skip to content

Commit

Permalink
Revert raise ClientDisconnected on HTTP (#2276) (#2276)
Browse files Browse the repository at this point in the history
* chore: revert #2220

* Don't revert the receive changes

---------

Co-authored-by: Marcelo Trylesinski <[email protected]>
  • Loading branch information
ninoseki and Kludex authored Mar 19, 2024
1 parent a05ae64 commit 76a3812
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 34 deletions.
20 changes: 0 additions & 20 deletions tests/protocols/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from uvicorn.lifespan.on import LifespanOn
from uvicorn.main import ServerState
from uvicorn.protocols.http.h11_impl import H11Protocol
from uvicorn.protocols.utils import ClientDisconnected

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


@pytest.mark.anyio
async def test_disconnect_on_send(http_protocol_cls: HTTPProtocol) -> None:
got_disconnected = False

async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):
try:
await send({"type": "http.response.start", "status": 200})
except ClientDisconnected:
nonlocal got_disconnected
got_disconnected = True

protocol = get_connected_protocol(app, http_protocol_cls)
protocol.data_received(SIMPLE_GET_REQUEST)
protocol.eof_received()
protocol.connection_lost(None)
await protocol.loop.run_one()
assert got_disconnected


@pytest.mark.anyio
async def test_early_response(http_protocol_cls: HTTPProtocol):
app = Response("Hello, world", media_type="text/plain")
Expand Down
5 changes: 1 addition & 4 deletions uvicorn/protocols/http/h11_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
service_unavailable,
)
from uvicorn.protocols.utils import (
ClientDisconnected,
get_client_addr,
get_local_addr,
get_path_with_query_string,
Expand Down Expand Up @@ -408,8 +407,6 @@ async def run_asgi(self, app: ASGI3Application) -> None:
result = await app( # type: ignore[func-returns-value]
self.scope, self.receive, self.send
)
except ClientDisconnected:
pass
except BaseException as exc:
msg = "Exception in ASGI application\n"
self.logger.error(msg, exc_info=exc)
Expand Down Expand Up @@ -458,7 +455,7 @@ async def send(self, message: ASGISendEvent) -> None:
await self.flow.drain()

if self.disconnected:
raise ClientDisconnected
return

if not self.response_started:
# Sending response status line and headers
Expand Down
12 changes: 2 additions & 10 deletions uvicorn/protocols/http/httptools_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
service_unavailable,
)
from uvicorn.protocols.utils import (
ClientDisconnected,
get_client_addr,
get_local_addr,
get_path_with_query_string,
Expand Down Expand Up @@ -412,8 +411,6 @@ async def run_asgi(self, app: ASGI3Application) -> None:
result = await app( # type: ignore[func-returns-value]
self.scope, self.receive, self.send
)
except ClientDisconnected:
pass
except BaseException as exc:
msg = "Exception in ASGI application\n"
self.logger.error(msg, exc_info=exc)
Expand Down Expand Up @@ -462,7 +459,7 @@ async def send(self, message: ASGISendEvent) -> None:
await self.flow.drain()

if self.disconnected:
raise ClientDisconnected
return

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

if self.disconnected or self.response_complete:
return {"type": "http.disconnect"}

message: HTTPRequestEvent = {
"type": "http.request",
"body": self.body,
"more_body": self.more_body,
}
message: HTTPRequestEvent = {"type": "http.request", "body": self.body, "more_body": self.more_body}
self.body = b""
return message

0 comments on commit 76a3812

Please sign in to comment.