hackney_h2_stream (hackney v4.4.1)
View Sourcegen_statem process for a single full-duplex HTTP/2 stream (gRPC-style bidirectional streaming).
This module mirrors hackney_wt / hackney_ws: an application gets a pid and uses send/recv (passive) or active-mode messages. It owns one dedicated HTTP/2 connection (negotiated via ALPN) and opens one stream on it whose events are routed here directly by the h2 library's per-stream handler mechanism, so the request body and the response can be sent and read interleaved on the same stream.
Send / receive
send/2,3 writes a DATA frame (optionally with END_STREAM via fin). send_trailers/2 closes the send side with trailing HEADERS (gRPC carries grpc-status there). recv/1,2 returns the next inbound message: {response, Status, Headers}, {data, Data}, {trailers, Trailers} or done (the peer ended the stream). After done, recv returns {error, closed}.
Delivery modes
Passive (default): messages are buffered and read with recv. Active ({active, true|once}): every message is forwarded to the owner as {hackney_h2, Pid, Msg}, and errors as {hackney_h2_error, Pid, Reason}.
Flow control
With {flow_control, manual} the receive window is only replenished by consume/2, so a slow reader applies backpressure to the peer. The default auto replenishes automatically.
States: idle (not yet connected), connected (ready), closed (stream/conn ended, buffered data still drainable).
Summary
Functions
Cancel the stream and tear down the connection.
Establish the connection and open the stream. Blocks until ready.
Acknowledge N consumed bytes (manual flow control only).
Assign a new controlling process.
Receive the next inbound message (passive mode only).
Send a DATA frame on the stream (no END_STREAM).
Send a DATA frame, optionally half-closing the send side (fin).
Send trailing HEADERS, half-closing the send side (gRPC trailers).
Set options. Supported: [{active, true|false|once}].
Start a stream process. See hackney:h2_open/3,4 for option docs.
Types
-type h2_msg() :: {response, non_neg_integer(), list()} | {data, binary()} | {trailers, list()} | done.
Functions
-spec close(pid()) -> ok.
Cancel the stream and tear down the connection.
Establish the connection and open the stream. Blocks until ready.
-spec consume(pid(), non_neg_integer()) -> ok | {error, term()}.
Acknowledge N consumed bytes (manual flow control only).
Assign a new controlling process.
Receive the next inbound message (passive mode only).
Send a DATA frame on the stream (no END_STREAM).
Send a DATA frame, optionally half-closing the send side (fin).
Send trailing HEADERS, half-closing the send side (gRPC trailers).
Set options. Supported: [{active, true|false|once}].
Start a stream process. See hackney:h2_open/3,4 for option docs.