libduvet/http/send

Types

What a request’s progress callback hears: the bytes of the body sent so far, and their total.

pub type Progress =
  fn(Int, Int) -> Nil

Why a request didn’t finish. The names and payloads carry what Dart’s TimeoutException, RequestAbortedException and the transport’s own errors carried, so logs and messages keep their shape.

pub type SendError {
  TimedOut(method: String, path: String, timeout_ms: Int)
  Aborted
  Network(String)
}

Constructors

  • TimedOut(method: String, path: String, timeout_ms: Int)

    Nothing moved for [timeout_ms] while sending [method] [path].

  • Aborted

    The caller’s abort trigger completed first.

  • Network(String)

    The connection failed or closed.

Values

pub const default_request_timeout: Int

How long a request may go without progress before it fails: connecting, each piece of its body sent and each piece of the answer received count as progress, so an upload that keeps moving isn’t cut short.

pub fn send_within(
  transport transport: fn(
    transport.Request,
    fn(Int) -> Nil,
    fn() -> Nil,
  ) -> Result(transport.Response, transport.ExchangeError),
  request request: transport.Request,
  timeout timeout_ms: Int,
  abort abort: option.Option(process.Subject(a)),
  on_progress on_progress: option.Option(fn(Int, Int) -> Nil),
) -> Result(transport.Response, SendError)

Sends [request] and reads the whole answer, in a process of its own so that the connection can be dropped mid-flight.

It fails with [TimedOut] when [timeout_ms] passes without progress, and with [Aborted] when [abort] receives first; either way the exchange’s process is killed, which closes its connection. [on_progress] hears the bytes sent so far and their total.

✨ Search Document