hairpin.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-hairpin@0.19.0.1/hairpin.bend as Hairpin
Hairpin: an HTTP client with a base URL, default headers, a pool, cookies, mTLS, redirects, and proven retries. Source: https://github.com/paymog/bend-kit/tree/main/hairpin
10 imports
import Base import ./pure.bend as Policy import bend-kit-http@0.45.0.1/http.bend as Http import bend-kit-http@0.45.0.1/pure.bend as Pure import bend-kit-time@0.3.0.4/pure.bend as Time import bend-kit-time@0.3.0.4/time.bend as Clock import bend-kit-url@0.4.1.0/url.bend as Url import bend-kit-json@0.7.3.1/json.bend as Json import bend-kit-bytes@0.3.3.2/bytes.bend as Bytes import bend-kit-retry@0.3.0.0/retry.bend as Retry
Types
type Opts source · line 15 · raw
Data
base: "" for none. headers: lowercase names. ms: the step timeout. policy: attempts, backoff, and deadline of each request. ca: a PEM CA file to trust; "" trusts the default store.
Opts@base:String -> @headers:Map<&2, List<&2, String>> -> @ms:U32 -> @mode:0xf0810503fa2a9fb55fa01b9145a73254/pure.Mode -> @policy:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @cert:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Cert> -> @ca:String -> Opts
type Client source · line 19 · raw
Type
breaker: the circuit breaker of every request on this client.
Client@opts:Opts -> @pool:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @jar:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @breaker:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> Client
type Err source · line 23 · raw
Data
ErrHttp: the last attempt failed. ErrDenied: no attempt started, for why.
ErrHttp@error:0xf0810503fa2a9fb55fa01b9145a73254/pure.Err -> Err
ErrDenied@why:0x14e48621ef66156b0eb652524b8594d4/retry.Deny -> Err
type Step source · line 142 · raw
@-R:Type -> Type
The live state of one request between attempts. R: a response or a stream. last: the result of the last attempt, None before the first.
Step@-R:Type -> @pool:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @jar:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @breaker:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @budget:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> @last:Maybe<&1, Result<&1, &1, Err, R>> -> @plan:0x14e48621ef66156b0eb652524b8594d4/retry.Plan -> Step<R>
type Call source · line 235 · raw
Data
The inputs of one attempt. u: the target, None when it is not absolute. headers: the merged headers.
Call@enc:String -> @method:String -> @u:Maybe<&2, 0x1f2d80f53f971b16c6de6a65cb1918ae/url.Abs> -> @headers:Map<&2, List<&2, String>> -> Call
Definitions
def policy source · line 28 · raw
0x14e48621ef66156b0eb652524b8594d4/retry.Policy
One attempt, the first included; backoff from 500 ms, doubled to at most 30 s; no deadline.
def new.with source · line 33 · raw
@+cap:U32 -> Client
A pool of up to cap idle sockets per origin, no base, no default headers, 30 s steps, follow redirects, no retries, and no circuit breaker.
def new source · line 36 · raw
Client
def base source · line 39 · raw
@c:Client -> @url:String -> Client
def header source · line 44 · raw
@c:Client -> @k:String -> @v:String -> Client
A default header. It replaces an earlier default of the same name; a request header of that name replaces it.
def timeout source · line 48 · raw
@c:Client -> @ms:U32 -> Client
def redirect source · line 52 · raw
@c:Client -> @mode:0xf0810503fa2a9fb55fa01b9145a73254/pure.Mode -> Client
def retry source · line 57 · raw
@c:Client -> @n:U32 -> Client
Up to n retries after the first attempt: n + 1 attempts in all.
def deadline source · line 62 · raw
@c:Client -> @ms:U32 -> Client
No attempt of a request starts ms or more after the request starts.
def circuit source · line 67 · raw
@c:Client -> @circ:0x14e48621ef66156b0eb652524b8594d4/retry.Circuit -> Client
A circuit breaker in front of every request, starting closed.
def breaker.of source · line 72 · raw
@c:Client -> Pair(Client, 0x14e48621ef66156b0eb652524b8594d4/retry.Breaker)
The breaker, for inspection.
def cert source · line 77 · raw
@c:Client -> @chain:String -> @key:String -> Client
Paths to a PEM client chain and its private key, presented to every HTTPS origin.
def ca source · line 82 · raw
@c:Client -> @path:String -> Client
Path to a PEM CA file, trusted in place of the default store. Like the certificate, it follows same-origin redirects only.
def jar source · line 87 · raw
@c:Client -> @jar:0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar -> Client
Every request stores and sends cookies through jar. Its clock moves to Http.clock.now() before each try.
def jar.of source · line 92 · raw
@c:Client -> Pair(Client, Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>)
The jar, if the client has one.
def close source · line 96 · raw
@c:Client -> IO(Unit)
def stream.close source · line 101 · raw
@c:Client -> @st:0xf0810503fa2a9fb55fa01b9145a73254/http.Stream -> IO(Client)
Close a stream from open.as. A body read to its end gives its connection to the client's pool.
def jar.now source · line 107 · raw
@j:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> IO(Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>)
def once.final source · line 116 · raw
@+enc:String -> @x:Pair(0xf0810503fa2a9fb55fa01b9145a73254/http.Pool, Pair(Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>, Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>)) -> IO(Pair(0xf0810503fa2a9fb55fa01b9145a73254/http.Pool, Pair(Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>, Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>)))
def once source · line 124 · raw
@+ms:U32 -> @+mode:0xf0810503fa2a9fb55fa01b9145a73254/pure.Mode -> @+cert:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Cert> -> @+ca:String -> @+enc:String -> @p:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @j:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @+method:String -> @+u:Maybe<&2, 0x1f2d80f53f971b16c6de6a65cb1918ae/url.Abs> -> @+headers:Map<&2, List<&2, String>> -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(0xf0810503fa2a9fb55fa01b9145a73254/http.Pool, Pair(Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>, Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>)))
One try: the redirect loop on the pool, with the jar, the certificate, and the CA file, then the body decoded.
def lift source · line 133 · raw
@-R:Type -> @r:Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R> -> Result<&1, &1, Err, R>
def clock source · line 147 · raw
@need:Bool -> IO(Nat)
The clock, read only when a decision depends on it; 0 otherwise, which no such decision reads.
def breaker.on source · line 154 · raw
@br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> Bool
def transient source · line 161 · raw
@o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> Bool
def some source · line 174 · raw
@m:Maybe<&2, Nat> -> Bool
def deadline.some source · line 181 · raw
@b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> Bool
def outcome.io source · line 186 · raw
@+idem:Bool -> @v:0xf17275049b29b3722b5e5ea19e62ec47/pure.Verdict -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)
The wall clock dates a Retry-After, so it is read only for Again.
def jitter.io source · line 200 · raw
@need:Bool -> IO(Nat)
Jitter for the backoff, drawn only when a retry may follow.
def settle.at source · line 209 · raw
@-R:Type -> @+now:Nat -> @+rnd:Nat -> @+p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @+n:Nat -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @+b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> @pool:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @jar:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @r:Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R> -> Step<R>
def settle.outcome source · line 214 · raw
@-R:Type -> @+p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @+n:Nat -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @+br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> @pool:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @jar:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @r:Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R> -> IO(Step<R>)
The attempt has ended: tell the breaker, and plan the next step.
def settle.judged source · line 221 · raw
@-R:Type -> @+p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @+idem:Bool -> @+n:Nat -> @br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> @pool:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @jar:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @j:Pair(Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>, 0xf17275049b29b3722b5e5ea19e62ec47/pure.Verdict) -> IO(Step<R>)
def try.res source · line 239 · raw
@o:Opts -> @call:Call -> @pool:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @jar:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(0xf0810503fa2a9fb55fa01b9145a73254/http.Pool, Pair(Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>, Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>)))
One attempt that reads a whole response: the redirect loop on the pool, with the jar and the certificate.
def try.stream source · line 247 · raw
@o:Opts -> @call:Call -> @pool:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @jar:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(0xf0810503fa2a9fb55fa01b9145a73254/http.Pool, Pair(Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>, Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, 0xf0810503fa2a9fb55fa01b9145a73254/http.Stream>)))
One attempt that opens a stream on the pool: the redirect loop with the mode, the jar, and the certificate, then the body decoded by enc.
def close.res source · line 257 · raw
@r:0xf0810503fa2a9fb55fa01b9145a73254/pure.Res -> IO(Unit)
def denied source · line 281 · raw
@-R:Type -> @why:0x14e48621ef66156b0eb652524b8594d4/retry.Deny -> @last:Maybe<&1, Result<&1, &1, Err, R>> -> Maybe<&1, Result<&1, &1, Err, R>>
def pause source · line 314 · raw
@ms:Nat -> IO(Unit)
def result.of source · line 340 · raw
@-R:Type -> @m:Maybe<&1, Result<&1, &1, Err, R>> -> Result<&1, &1, Err, R>
def request.done source · line 347 · raw
@-R:Type -> @+o:Opts -> @s:Step<R> -> Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, R>))
def attempts source · line 351 · raw
@p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> Nat
def budget source · line 356 · raw
@c:Client -> IO(Pair(Client, 0x14e48621ef66156b0eb652524b8594d4/retry.Budget))
The budget of one plain request: the policy's attempts, and its deadline from now. The clock is read only for a deadline.
def request.in source · line 397 · raw
@c:Client -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+method:String -> @url:String -> @headers:Map<&2, List<&2, String>> -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>)))
request.as with judge, the idempotency of method, and every coding Http decodes.
def request.drop source · line 403 · raw
@x:Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>)) -> Pair(Client, Result<&1, &1, Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>)
def request.budget source · line 407 · raw
@+method:String -> @url:String -> @headers:Map<&2, List<&2, String>> -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> @x:Pair(Client, 0x14e48621ef66156b0eb652524b8594d4/retry.Budget) -> IO(Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>)))
def request source · line 417 · raw
@c:Client -> @+method:String -> @url:String -> @headers:Map<&2, List<&2, String>> -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(Client, Result<&1, &1, Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>))
url resolves against the base; headers go over the defaults. Redirects follow the client's mode, at most 20. Each request gets a fresh budget from budget(c). Before each attempt the deadline, the budget, and the breaker must admit it. GET, HEAD, OPTIONS, TRACE, PUT, and DELETE try again after a connect error, a timeout, or 408, 429, 500, 502, 503, or 504, as Pure.retry.judge says, on the same pool. When the attempts run out, the last result comes back; when none started, ErrDenied says why.
def get source · line 424 · raw
@c:Client -> @url:String -> IO(Pair(Client, Result<&1, &1, Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>))
def post.json source · line 428 · raw
@c:Client -> @url:String -> @v:0x24fdc97c15da7903c115e8c30af2a72d/json.Val -> IO(Pair(Client, Result<&1, &1, Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>))
POST v as compact JSON, with content-type: application/json.
Templates
template settle source · line 228 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R> -> Pair(Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>, 0xf17275049b29b3722b5e5ea19e62ec47/pure.Verdict)) -> @+p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @+idem:Bool -> @+n:Nat -> @br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> @x:Pair(0xf0810503fa2a9fb55fa01b9145a73254/http.Pool, Pair(Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>, Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>)) -> IO(Step<R>)
template close.last source · line 260 · raw
@-R:Type -> @-close:(@_:R -> IO(Unit)) -> @last:Maybe<&1, Result<&1, &1, Err, R>> -> IO(Unit)
template attempt.run source · line 271 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R> -> Pair(Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>, 0xf17275049b29b3722b5e5ea19e62ec47/pure.Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @_:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @_:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(0xf0810503fa2a9fb55fa01b9145a73254/http.Pool, Pair(Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>, Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>)))) -> @+o:Opts -> @+call:Call -> @+idem:Bool -> @+n:Nat -> @pool:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @jar:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @r:Pair(0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes, 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes) -> IO(Step<R>)
template attempt.gate source · line 289 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R> -> Pair(Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>, 0xf17275049b29b3722b5e5ea19e62ec47/pure.Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @_:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @_:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(0xf0810503fa2a9fb55fa01b9145a73254/http.Pool, Pair(Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>, Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>)))) -> @-close:(@_:R -> IO(Unit)) -> @x:Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Breaker, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, 0x14e48621ef66156b0eb652524b8594d4/retry.Gate)) -> @+o:Opts -> @+call:Call -> @+idem:Bool -> @+n:Nat -> @pool:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @jar:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> @last:Maybe<&1, Result<&1, &1, Err, R>> -> IO(Step<R>)
A refused stream closes only when the next attempt is admitted, so a denied attempt still returns it.
template attempt source · line 305 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R> -> Pair(Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>, 0xf17275049b29b3722b5e5ea19e62ec47/pure.Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @_:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @_:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(0xf0810503fa2a9fb55fa01b9145a73254/http.Pool, Pair(Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>, Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>)))) -> @-close:(@_:R -> IO(Unit)) -> @+o:Opts -> @+call:Call -> @+idem:Bool -> @+n:Nat -> @s:Step<R> -> IO(Step<R>)
Ask the gate; when it admits, make attempt n (0 first) of this layer. With no deadline and no breaker, admission does not read the clock.
template go source · line 322 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R> -> Pair(Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>, 0xf17275049b29b3722b5e5ea19e62ec47/pure.Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @_:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @_:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(0xf0810503fa2a9fb55fa01b9145a73254/http.Pool, Pair(Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>, Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>)))) -> @-close:(@_:R -> IO(Unit)) -> @left:Nat -> @+n:Nat -> @+o:Opts -> @+call:Call -> @+idem:Bool -> @s:Step<R> -> IO(Step<R>)
left: attempts this layer may still make. n: attempts made so far. Each turn follows the plan of the last step.
template run source · line 363 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R> -> Pair(Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>, 0xf17275049b29b3722b5e5ea19e62ec47/pure.Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0xf0810503fa2a9fb55fa01b9145a73254/http.Pool -> @_:Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar> -> @_:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(0xf0810503fa2a9fb55fa01b9145a73254/http.Pool, Pair(Maybe<&2, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Jar>, Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, R>)))) -> @-close:(@_:R -> IO(Unit)) -> @c:Client -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+idem:Bool -> @enc:String -> @method:String -> @url:String -> @headers:Map<&2, List<&2, String>> -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, R>)))
template request.as source · line 381 · raw
@-judge:(@_:Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res> -> Pair(Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>, 0xf17275049b29b3722b5e5ea19e62ec47/pure.Verdict)) -> @c:Client -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+idem:Bool -> @+enc:String -> @+method:String -> @url:String -> @headers:Map<&2, List<&2, String>> -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Res>)))
One request inside a caller's retry layer, with every choice explicit. Every attempt takes from b, the caller's shared budget, and obeys its deadline; the client's own policy caps the attempts of this call. The budget left comes back beside the result: pass it to the next call, so nested layers never reset or multiply it. The client's own deadline does not apply here; b's does. judge: the Verdict on each attempt; Policy.judge is the default. idem: the request is safe to repeat, so Again is retried; else the breaker counts it and it never repeats. enc: the Accept-Encoding codings.
template open.as source · line 391 · raw
@-judge:(@_:Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, 0xf0810503fa2a9fb55fa01b9145a73254/http.Stream> -> Pair(Result<&1, &1, 0xf0810503fa2a9fb55fa01b9145a73254/pure.Err, 0xf0810503fa2a9fb55fa01b9145a73254/http.Stream>, 0xf17275049b29b3722b5e5ea19e62ec47/pure.Verdict)) -> @c:Client -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+idem:Bool -> @+enc:String -> @+method:String -> @url:String -> @headers:Map<&2, List<&2, String>> -> @body:0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes -> IO(Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, 0xf0810503fa2a9fb55fa01b9145a73254/http.Stream>)))
A streamed request under the same budget, deadline, backoff, and breaker as request.as. The stream opens on the client's pool. It follows the client's redirect mode, presents its certificate, and sends and stores cookies through its jar, as request.as does. judge reads the status and headers through Http.stream.res. A refused stream closes before the next attempt; the last one comes back open, so the caller can read its body. Close it with stream.close to give its connection back to the pool.