Skip to content

Commit e87578d

Browse files
committed
Update vendored httpx-ws to upstream v0.9.0 (0341891)
The initial vendoring in #1042 accidentally used frankie567/httpx-ws@6bc568b (v0.6.2 era, October 2024), missing 80 upstream commits. This ports every upstream change from that point to the current tip, frankie567/httpx-ws@0341891 (v0.9.0 + 6 commits). See discussion #1066. Highlights: - Serialize stream writes with a write lock (httpx-ws#29) - Rebuild the async session on anyio.AsyncContextManagerMixin, fixing the asyncio hang on exit after cancellation and cancel scope corruption (httpx-ws#108); requires anyio>=4.10 - Rewrite ASGIWebSocketTransport on a task group and anyio streams instead of a blocking portal and queue.Queue - Support the WebSocket Denial Response ASGI extension - Add a configurable initial_receive_timeout with a clear error when the server never accepts - Raise TimeoutError instead of queue.Empty on sync receive timeout - Handle end of stream and closing-state keepalive pings properly - Add class-based WebSocketClient/AsyncWebSocketClient with session_class support (kept off connect_ws/aconnect_ws, where mypy cannot infer the TypeVar default through the contextmanager decorator) Two fixes not in upstream: register aclose before the initial receive so a never-accepting app does not leak memory object streams, and cover the double-__aenter__ guard with a test.
1 parent 95aebc3 commit e87578d

9 files changed

Lines changed: 894 additions & 345 deletions

File tree

docs/websockets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ The `receive` methods block until a message is available. Pass a `timeout` in se
6666
>>> ws.receive_text(timeout=2.0)
6767
```
6868

69-
If no message arrives in time, the sync session raises `queue.Empty`, while the async session raises `TimeoutError`.
69+
If no message arrives in time, `TimeoutError` is raised.
7070

7171
If the received message doesn't match the expected type, `WebSocketInvalidTypeReceived` is raised.
7272

src/httpx2/httpx2/websockets/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
Copyright (c) 2021 François Voron, MIT License (https://github.com/frankie567/httpx-ws/blob/main/LICENSE).
55
"""
66

7-
from ._api import AsyncWebSocketSession, JSONMode, WebSocketSession
7+
from ._api import (
8+
AsyncWebSocketClient,
9+
AsyncWebSocketSession,
10+
JSONMode,
11+
WebSocketClient,
12+
WebSocketSession,
13+
)
814
from ._exceptions import (
915
HTTPXWSException,
1016
WebSocketDisconnect,
@@ -16,9 +22,11 @@
1622

1723
__all__ = [
1824
"ASGIWebSocketTransport",
25+
"AsyncWebSocketClient",
1926
"AsyncWebSocketSession",
2027
"HTTPXWSException",
2128
"JSONMode",
29+
"WebSocketClient",
2230
"WebSocketDisconnect",
2331
"WebSocketInvalidTypeReceived",
2432
"WebSocketNetworkError",

0 commit comments

Comments
 (0)