h1_upgrade (h1 v0.2.1)

View Source

HTTP/1.1 Upgrade + capsule passthrough helpers.

Upgrade handshake itself is done by h1_connection (client: h1:upgrade/3,4; server: h1:accept_upgrade/3). After a successful handshake the caller owns the raw socket and any leftover buffer.

This module provides the thin capsule-over-socket helpers a consumer (e.g. masque for RFC 9298 CONNECT-UDP) needs on that raw socket: framing a capsule and reading one back, with an incremental buffer so partial reads don't drop bytes.

The capsule wire format (RFC 9297) lives in h1_capsule. This module stays protocol-agnostic — it knows nothing about connect-udp, connect-ip, or any specific capsule type.

Summary

Functions

Read exactly one capsule from the socket, reusing any bytes already in Buffer. Returns the decoded capsule plus the leftover buffer, ready to be passed back into the next call.

Encode a capsule and send it on the raw socket.

Types

capsule/0

-type capsule() :: {atom() | non_neg_integer(), binary()}.

socket/0

-type socket() :: gen_tcp:socket() | ssl:sslsocket().

transport/0

-type transport() :: gen_tcp | ssl.

Functions

close(_, S)

-spec close(transport(), socket()) -> ok.

recv_capsule(Transport, Socket, Buffer)

-spec recv_capsule(transport(), socket(), binary()) -> {ok, capsule(), binary()} | {error, term()}.

Read exactly one capsule from the socket, reusing any bytes already in Buffer. Returns the decoded capsule plus the leftover buffer, ready to be passed back into the next call.

recv_capsule(Transport, Socket, Buffer, Timeout)

-spec recv_capsule(transport(), socket(), binary(), timeout()) ->
                      {ok, capsule(), binary()} | {error, term()}.

send_capsule(Transport, Socket, Type, Payload)

-spec send_capsule(transport(), socket(), atom() | non_neg_integer(), iodata()) -> ok | {error, term()}.

Encode a capsule and send it on the raw socket.