Process-backed readable stream used for Fetch-style response and request bodies.
Streamed responses expose this PID in HTTP.Response.body. Streaming uploads can
pass a stream PID as body when HTTP.fetch/2 is called with duplex: "half".
Producers write chunks with chunk/3 and finish with finish/1; consumers read
by sending {:read_chunk, pid} or {:read_chunk, pid, :ack}.
Summary
Functions
Finishes a stream with ordered trailer fields (a list or HTTP.Headers).
Creates a stream from an enumerable.
Sends response trailers to the reader before the terminal stream event.
Functions
@spec finish(pid()) :: :ok
@spec finish(pid(), HTTP.Headers.t() | HTTP.Headers.headers_list()) :: :ok | {:error, term()}
Finishes a stream with ordered trailer fields (a list or HTTP.Headers).
Validation limits trailers to 128 fields and 65,536 serialized bytes. Invalid
trailers return an error without finishing the stream. For HTTP/1 uploads,
every field must be declared in the request's Trailer header and the body
must use chunk framing (no Content-Length). HTTP/2 uploads send trailing
HEADERS after acknowledged DATA; fixed content length counts DATA bytes only.
HTTP/3 uploads send ordered trailing HEADERS with FIN after acknowledged DATA;
valid Trailer declarations are optional.
Completion is signalled asynchronously, like finish/1.
@spec from_enumerable(Enumerable.t(), keyword()) :: {:ok, pid()} | {:error, term()}
Creates a stream from an enumerable.
Pass telemetry: false in the optional second argument to silence producer
streaming events. The default is true.
Each enumerable item is converted to binary and emitted with backpressure. The returned PID can be passed as a streaming request body:
{:ok, stream} = HTTP.Stream.from_enumerable(["hello", " ", "world"])
HTTP.fetch(url, method: :post, body: stream, duplex: "half")
@spec start_link(non_neg_integer()) :: {:ok, pid()}
Sends response trailers to the reader before the terminal stream event.