Nous.HTTP.StreamBackend.Req (nous v0.16.4)

View Source

Nous.HTTP.StreamBackend implementation backed by Req (Finch underneath).

Default streaming backend. Drives Req.post/1 with the :into callback so chunks are pushed into a Task, which forwards them to the consuming Stream.resource via send/2.

Backpressure

Req's :into callback runs in the spawned Task. Forwarding to the consumer process is send/2, so a fast producer + slow consumer can grow the consumer's mailbox.

The producer task watches the consumer's mailbox via Process.info(parent, :message_queue_len). When the queue length crosses @backpressure_high_water (default 1_000 chunks) the task busy-waits in 5ms increments until it drops below @backpressure_low_water (default 100). This gives Req's :into callback natural backpressure — the producing socket doesn't read more bytes while we're waiting — without requiring the consumer to switch to the Hackney backend.

If the consumer is truly unresponsive (the mailbox stays high for longer than :backpressure_max_wait_ms), the task emits {:backpressure_overflow, %{queue_len: n}} and aborts the stream rather than wedging forever.

Callers whose downstream consumers reliably block per chunk (LiveView fan-out under load, persistence-on-every-chunk, slow IO) can still prefer Nous.HTTP.StreamBackend.Hackney, which provides strict pull-based backpressure via :hackney's {:async, :once} mode.

TLS verification

Req's defaults handle TLS verification via Mint/Finch (system CAs with peer verification). No additional configuration needed.