hackney_h3 (hackney v4.2.3)
View SourceHTTP/3 support for hackney.
This module provides HTTP/3 functionality using pure Erlang QUIC. It handles stream management, header encoding, and request/response handling for HTTP/3 connections over QUIC.
Usage
%% Make a simple GET request
{ok, Status, Headers, Body} = hackney_h3:request(get, "https://cloudflare.com/")
%% Make a request with options
{ok, Status, Headers, Body} = hackney_h3:request(get, "https://example.com/",
[{<<"user-agent">>, <<"hackney/2.0">>}], <<>>, #{timeout => 30000})
Summary
Functions
Wait for an HTTP/3 response.
Close the HTTP/3 connection.
Close the HTTP/3 connection with a reason.
Connect to an HTTP/3 server.
Connect to an HTTP/3 server with options. lsquic handles its own UDP socket creation and DNS resolution.
Whether the server accepted 0-RTT early data, or unknown before the handshake completes.
Finish sending body (close stream for writing).
Return the last session ticket delivered for this connection, or undefined if none has arrived yet. See wait_session_ticket/2 to block until one is available.
Get the state of a specific stream.
Check if HTTP/3/QUIC support is available. Always returns true as pure Erlang implementation is always available.
Parse response headers from a QUIC stream_headers event. Returns {ok, Status, ResponseHeaders} or {error, Reason}.
Make an HTTP/3 request with default options.
Make an HTTP/3 request with headers.
Make an HTTP/3 request with headers and body.
Make an HTTP/3 request with all options.
Send a chunk of body data on a stream.
Send a complete HTTP/3 request (headers + body). Returns {ok, StreamId, UpdatedStreams} or {error, Reason}.
Send HTTP/3 request headers only (for streaming body). Returns {ok, StreamId, UpdatedStreams} or {error, Reason}.
Update the state of a stream.
Block until a session ticket is delivered to the owner, up to Timeout ms. The caller must be the connection owner (the process that called connect/4). Returns {ok, Ticket} or {error, timeout}.
Types
-type h3_conn() :: reference().
-type stream_id() :: non_neg_integer().
-type streams_map() :: #{stream_id() => {term(), stream_state()}}.
Functions
-spec await_response(reference(), non_neg_integer()) -> {ok, integer(), headers(), binary()} | {error, term()}.
Wait for an HTTP/3 response.
-spec close(h3_conn()) -> ok.
Close the HTTP/3 connection.
Close the HTTP/3 connection with a reason.
-spec connect(binary() | string(), inet:port_number()) -> {ok, reference()} | {error, term()}.
Connect to an HTTP/3 server.
-spec connect(binary() | string(), inet:port_number(), map()) -> {ok, reference()} | {error, term()}.
Connect to an HTTP/3 server with options. lsquic handles its own UDP socket creation and DNS resolution.
Whether the server accepted 0-RTT early data, or unknown before the handshake completes.
-spec finish_send_body(h3_conn(), stream_id(), streams_map()) -> {ok, streams_map()} | {error, term()}.
Finish sending body (close stream for writing).
-spec get_fd(gen_udp:socket()) -> {ok, integer()} | {error, term()}.
Return the last session ticket delivered for this connection, or undefined if none has arrived yet. See wait_session_ticket/2 to block until one is available.
-spec get_stream_state(stream_id(), streams_map()) -> {ok, {term(), stream_state()}} | {error, not_found}.
Get the state of a specific stream.
-spec handle_timeout(reference(), non_neg_integer()) -> non_neg_integer() | infinity.
-spec is_available() -> true.
Check if HTTP/3/QUIC support is available. Always returns true as pure Erlang implementation is always available.
Parse response headers from a QUIC stream_headers event. Returns {ok, Status, ResponseHeaders} or {error, Reason}.
-spec peername(reference()) -> {ok, {inet:ip_address(), inet:port_number()}} | {error, term()}.
-spec process(reference()) -> non_neg_integer() | infinity.
Make an HTTP/3 request with default options.
Make an HTTP/3 request with headers.
Make an HTTP/3 request with headers and body.
Make an HTTP/3 request with all options.
Options: - timeout: Request timeout in milliseconds (default: 30000) - recv_timeout: Response receive timeout (default: 30000) - follow_redirect: boolean to follow redirects (default: false) - max_redirect: maximum number of redirects to follow (default: 5)
-spec reset_stream(reference(), non_neg_integer(), non_neg_integer()) -> ok | {error, term()}.
Send a chunk of body data on a stream.
-spec send_data(reference(), non_neg_integer(), iodata(), boolean()) -> ok | {error, term()}.
-spec send_request(h3_conn(), method(), binary(), binary(), headers(), binary()) -> {ok, stream_id(), streams_map()} | {error, term()}.
Send a complete HTTP/3 request (headers + body). Returns {ok, StreamId, UpdatedStreams} or {error, Reason}.
-spec send_request_headers(h3_conn(), method(), binary(), binary(), headers()) -> {ok, stream_id(), streams_map()} | {error, term()}.
Send HTTP/3 request headers only (for streaming body). Returns {ok, StreamId, UpdatedStreams} or {error, Reason}.
-spec sockname(reference()) -> {ok, {inet:ip_address(), inet:port_number()}} | {error, term()}.
-spec update_stream_state(stream_id(), {term(), stream_state()}, streams_map()) -> streams_map().
Update the state of a stream.
Block until a session ticket is delivered to the owner, up to Timeout ms. The caller must be the connection owner (the process that called connect/4). Returns {ok, Ticket} or {error, timeout}.