Skip to content

Commit

Permalink
chore: revert encode#2220
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki committed Mar 16, 2024
1 parent a05ae64 commit a77ff72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 35 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
22 changes: 11 additions & 11 deletions uvicorn/protocols/http/httptools_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ASGI3Application,
ASGIReceiveEvent,
ASGISendEvent,
HTTPDisconnectEvent,
HTTPRequestEvent,
HTTPResponseBodyEvent,
HTTPResponseStartEvent,
Expand All @@ -29,7 +30,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 +412,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 +460,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 @@ -571,13 +569,15 @@ async def receive(self) -> ASGIReceiveEvent:
await self.message_event.wait()
self.message_event.clear()

message: HTTPDisconnectEvent | HTTPRequestEvent
if self.disconnected or self.response_complete:
return {"type": "http.disconnect"}
message = {"type": "http.disconnect"}
else:
message = {
"type": "http.request",
"body": self.body,
"more_body": self.more_body,
}
self.body = b""

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

0 comments on commit a77ff72

Please sign in to comment.