Update vendored httpx-ws to upstream v0.9.0

Merged
KL
3mo ago
+894-345

Closes the gap reported in #1066: the vendoring in #1042 accidentally used frankie567/httpx-ws@6bc568b (v0.6.2 era, October 2024). This ports every upstream change from there to the current tip, frankie567/httpx-ws@0341891 (v0.9.0 + 6 commits) - 80 commits, of which 38 touch library or test code; the rest are upstream CI/docs/tooling.

What comes in

  • Write lock serializing stream writes (httpx-ws#29)
  • Async session rebuilt on anyio.AsyncContextManagerMixin, fixing the asyncio hang on exit after cancellation and cancel scope corruption (httpx-ws#108); anyio>=4.10 is now required
  • ASGIWebSocketTransport rewritten on a task group and anyio streams instead of a blocking portal and queue.Queue
  • WebSocket Denial Response ASGI extension support
  • Configurable initial_receive_timeout with a clear error when the server never calls accept()
  • TimeoutError instead of queue.Empty on sync receive timeout (docs updated)
  • Proper end-of-stream handling and keepalive ping exit when the connection is closing
  • Class-based WebSocketClient/AsyncWebSocketClient with session_class support, exported from httpx2.websockets

Deliberate deviations from upstream

  • httpx2 adaptations preserved: relative imports, lazy httpcore2 imports, explicit handshake parameters instead of **kwargs, Client.websocket() as the public entry point (connect_ws/aconnect_ws stay unexported)
  • session_class lives only on the client classes, not on connect_ws/aconnect_ws: mypy cannot infer the PEP 696 TypeVar default through the contextmanager decorator
  • Two fixes upstream does not have (worth PRing back): aclose is registered before the initial receive so a never-accepting app does not leak memory object streams, and the double-__aenter__ guard is covered by a test

Verification

  • 164 websocket tests pass on asyncio and trio, 3 consecutive full runs; whole httpx2 suite: 1634 passed
  • 100% coverage on all websockets/ files; ruff format, ruff check, mypy strict, unasync all clean
  • Independently reviewed by Codex against the full upstream commit range: all 38 code commits verified present, no porting bugs found

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.