HTTP.Stream (http_fetch v0.11.0)

View Source

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

chunk(pid, chunk, timeout \\ HTTP.Config.streaming_timeout())

@spec chunk(pid(), binary(), timeout()) :: :ok | {:error, term()}

error(pid, reason)

@spec error(pid(), term()) :: :ok

finish(pid)

@spec finish(pid()) :: :ok

from_enumerable(enumerable)

@spec from_enumerable(Enumerable.t()) :: {:ok, pid()} | {:error, term()}

Creates a stream from an enumerable.

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")

start_link(content_length)

@spec start_link(non_neg_integer()) :: {:ok, pid()}