Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Revert raise ClientDisconnected on HTTP (#2276) #2276

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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