Add HTTP/2 full-duplex bidirectional stream API (h2_*)#876
Merged
Conversation
dc85210 to
4402b3d
Compare
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.
4402b3d to
a6f699d
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 existingws_*andwt_*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_recvyields{response, Status, Headers}/{data, Data}/{trailers, Trailers}/done.{active, true|once}delivers the same as{hackney_h2, Pid, Msg}.{flow_control, manual}plush2_consume/2applies receive backpressure.The new
hackney_h2_streamgen_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 bypasseshackney_conn's linear request/response lifecycle.hackney_conngains an additiveopen_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.