blackbull.client.websocket_h2¶
blackbull.client.websocket_h2
¶
RFC 8441 WebSocket client over one HTTP/2 stream.
The peer must advertise ENABLE_CONNECT_PROTOCOL. Reuse the connection factory and flow control; a second HPACK context corrupts sibling streams.
WebSocketH2Client
¶
Async WebSocket-over-HTTP/2 client (RFC 8441).
Owns the TLS + HTTP/2 connection; performs the Extended CONNECT
handshake (:method=CONNECT, :protocol=websocket) on
connect and returns a WebSocketH2Session for
post-handshake frame I/O.
The peer server must advertise SETTINGS_ENABLE_CONNECT_PROTOCOL=1;
BlackBull's server does so when BB_H2_ENABLE_WEBSOCKET=1.
connect_status
property
¶
:status from the last Extended CONNECT response, or None
if connect has not run yet.
frame_factory
property
¶
Reuse the HTTP2Client connection's HPACK context.
Raise RuntimeError before entering the connection context.
connect(path='/', *, response_timeout=5.0)
async
¶
Run the RFC 8441 Extended CONNECT handshake on this connection.
Returns a WebSocketH2Session bound to the new H2 stream.
Raises HandshakeError on a non-200 :status response
or TimeoutError if no response arrives within
response_timeout.
WebSocketH2Session
¶
Frame-level WebSocket session over one HTTP/2 stream.
Outgoing frames are masked (RFC 6455 §5.1) and wrapped in H2 DATA
frames. Incoming DATA payloads feed the shared
WebSocketRecipient stack through _H2QueueReader —
fragmentation reassembly, FIN/RSV/mask
validation, UTF-8 checks, and auto-PONG all come from the same
codec the server and the H1 client use.
close(code=_CLOSE_CODE_NORMAL, *, drain_timeout=5.0)
async
¶
Send a WebSocket close frame (END_STREAM on the carrying DATA frame), await the peer's echoed CLOSE bounded by drain_timeout, and stop the recipient's reader task. Idempotent.
Same close discipline as the H1
client's WebSocketSession.close.
receive(timeout=5.0)
async
¶
Return (opcode, payload) for the next complete WebSocket
message on this stream (fragmented messages are reassembled;
PING is answered transparently).
Raises TimeoutError if no message arrives within
timeout. Returned opcodes match
blackbull.server.ws_codec.WSOpcode; a peer CLOSE (or
stream end) is surfaced as (WSOpcode.CLOSE, 2-byte code).