Skip to content

Add HTTP/2 full-duplex bidirectional stream API (h2_*)#876

Merged
benoitc merged 1 commit into
masterfrom
feature/http2-bidi-streams
Jun 13, 2026
Merged

Add HTTP/2 full-duplex bidirectional stream API (h2_*)#876
benoitc merged 1 commit into
masterfrom
feature/http2-bidi-streams

Conversation

@benoitc

@benoitc benoitc commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Adds an h2_* API for gRPC-style bidirectional HTTP/2 streams, where the client sends and receives interleaved on a single stream. It mirrors the existing ws_* and wt_* APIs.

{ok, S} = hackney:h2_open(URL, Headers, Opts),
{ok, {response, 200, _}} = hackney:h2_recv(S),
ok = hackney:h2_send(S, Frame1),
{ok, {data, Reply1}} = hackney:h2_recv(S),
ok = hackney:h2_send(S, <<>>, fin),
{ok, {trailers, T}} = hackney:h2_recv(S),
{ok, done} = hackney:h2_recv(S),
ok = hackney:h2_close(S).

h2_recv yields {response, Status, Headers} / {data, Data} / {trailers, Trailers} / done. {active, true|once} delivers the same as {hackney_h2, Pid, Msg}. {flow_control, manual} plus h2_consume/2 applies receive backpressure.

The new hackney_h2_stream gen_statem owns one dedicated h2 connection and opens a stream routed to itself via the h2 library's per-stream handler, so the bidi data plane bypasses hackney_conn's linear request/response lifecycle. hackney_conn gains an additive open_h2_stream/6; existing request paths are untouched.

Follow-up to #875 (HTTP/2 streaming bodies). The API carries raw bytes; gRPC message framing is the caller's responsibility.

@benoitc benoitc force-pushed the feature/http2-bidi-streams branch from dc85210 to 4402b3d Compare June 13, 2026 13:32
Add an h2_* API for gRPC-style bidirectional HTTP/2 streams, where the
client sends and receives interleaved on one stream. It mirrors the ws_*
and wt_* APIs: h2_open returns a pid, h2_send writes DATA frames, h2_recv
reads inbound messages, h2_send_trailers and h2_send(_, _, fin) half-close
the send side, and h2_consume applies receive backpressure under
{flow_control, manual}. Passive recv and {active, true|once} delivery are
both supported.

The new hackney_h2_stream gen_statem owns one dedicated h2 connection and
opens a stream on it routed to itself via the h2 library's per-stream
handler, so the bidi data plane bypasses hackney_conn's linear lifecycle.
hackney_conn gains an additive open_h2_stream/6 that builds the request
headers and registers the handler; existing request paths are untouched.
@benoitc benoitc force-pushed the feature/http2-bidi-streams branch from 4402b3d to a6f699d Compare June 13, 2026 13:39
@benoitc benoitc merged commit 7f85d2c into master Jun 13, 2026
6 checks passed
@benoitc benoitc deleted the feature/http2-bidi-streams branch June 13, 2026 13:44
@benoitc benoitc mentioned this pull request Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant