hairpin.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-hairpin@0.17.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
9 imports
import Base import bend-kit-http@0.44.0.2/http.bend as Http import bend-kit-http@0.44.0.2/pure.bend as Pure import bend-kit-time@0.3.0.3/pure.bend as Time import bend-kit-time@0.3.0.3/time.bend as Clock import bend-kit-url@0.4.1.0/url.bend as Url import bend-kit-json@0.7.3.0/json.bend as Json import bend-kit-bytes@0.3.3.1/bytes.bend as Bytes import bend-kit-retry@0.3.0.0/retry.bend as Retry
Types
type Opts source · line 14 · 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:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Mode -> @policy:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @cert:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Cert> -> @ca:String -> Opts
type Client source · line 18 · raw
Type
breaker: the circuit breaker of every request on this client.
Client@opts:Opts -> @pool:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @jar:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @breaker:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> Client
type Err source · line 22 · raw
Data
ErrHttp: the last attempt failed. ErrDenied: no attempt started, for why.
ErrHttp@error:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err -> Err
ErrDenied@why:0x14e48621ef66156b0eb652524b8594d4/retry.Deny -> Err
type Verdict source · line 165 · raw
Data
A judge's verdict on one attempt. Ok: a success. Caller: the request is at fault (a 4xx), so it stops and the breaker does not count it. Target: the target failed in a way another try would repeat, so it stops and the breaker counts it. Again: another try may help; after is the Retry-After value, "" for none.
VerdictOkVerdict
VerdictCallerVerdict
VerdictTargetVerdict
VerdictAgain@after:String -> Verdict
type Step source · line 192 · 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:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @jar:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @breaker:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @budget:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @last:Maybe<&1, Result<&1, &1, Err, R>> -> @plan:0x14e48621ef66156b0eb652524b8594d4/retry.Plan -> Step<R>
type Call source · line 309 · 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 27 · 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 32 · 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 35 · raw
Client
def base source · line 38 · raw
@c:Client -> @url:String -> Client
def header source · line 43 · 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 47 · raw
@c:Client -> @ms:U32 -> Client
def redirect source · line 51 · raw
@c:Client -> @mode:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Mode -> Client
def retry source · line 56 · raw
@c:Client -> @n:U32 -> Client
Up to n retries after the first attempt: n + 1 attempts in all.
def deadline source · line 61 · raw
@c:Client -> @ms:U32 -> Client
No attempt of a request starts ms or more after the request starts.
def circuit source · line 66 · raw
@c:Client -> @circ:0x14e48621ef66156b0eb652524b8594d4/retry.Circuit -> Client
A circuit breaker in front of every request, starting closed.
def breaker.of source · line 71 · raw
@c:Client -> Pair(Client, 0x14e48621ef66156b0eb652524b8594d4/retry.Breaker)
The breaker, for inspection.
def cert source · line 76 · 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 81 · 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 86 · raw
@c:Client -> @jar:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/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 91 · raw
@c:Client -> Pair(Client, Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>)
The jar, if the client has one.
def close source · line 95 · raw
@c:Client -> IO(Unit)
def stream.close source · line 100 · raw
@c:Client -> @st:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/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 target.pick source · line 106 · raw
@none:Bool -> @b:String -> @ref:String -> Maybe<&2, String>
def target source · line 114 · raw
@+b:String -> @ref:String -> Maybe<&2, String>
ref against the base (RFC 3986 §5.2); with no base, ref as given. None when the base is not absolute.
def target.abs source · line 117 · raw
@m:Maybe<&2, String> -> Maybe<&2, 0x1f2d80f53f971b16c6de6a65cb1918ae/url.Abs>
def merge source · line 126 · raw
@defaults:Map<&2, List<&2, String>> -> @headers:Map<&2, List<&2, String>> -> Map<&2, List<&2, String>>
The defaults under the request headers, names lowercased; a request header replaces a default of its name. Host, Connection, Content-Length, and Transfer-Encoding are the client's own, so both sides drop them.
def jar.now source · line 129 · raw
@j:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> IO(Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>)
def once.final source · line 138 · raw
@+enc:String -> @x:Pair(0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool, Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>, Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>)) -> IO(Pair(0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool, Pair(Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>, Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>)))
def once source · line 146 · raw
@+ms:U32 -> @+mode:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Mode -> @+cert:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Cert> -> @+ca:String -> @+enc:String -> @p:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @j:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @+method:String -> @+u:Maybe<&2, 0x1f2d80f53f971b16c6de6a65cb1918ae/url.Abs> -> @+headers:Map<&2, List<&2, String>> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool, Pair(Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>, Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>)))
One try: the redirect loop on the pool, with the jar, the certificate, and the CA file, then the body decoded.
def hint.ms source · line 155 · raw
@m:Maybe<&2, U32> -> Maybe<&2, Nat>
def outcome source · line 172 · raw
@+idem:Bool -> @v:Verdict -> @now:0xf6004ed2773adf12acc8863c4d424242/pure.Instant -> 0x14e48621ef66156b0eb652524b8594d4/retry.Outcome
Ok is Settled, Caller is Rejected, and Target is Failed. Again is Transient for an idempotent request, else Unsafe.
def lift source · line 183 · raw
@-R:Type -> @r:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R> -> Result<&1, &1, Err, R>
def clock source · line 197 · 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 204 · raw
@br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> Bool
def transient source · line 211 · raw
@o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> Bool
def some source · line 224 · raw
@m:Maybe<&2, Nat> -> Bool
def deadline.some source · line 231 · raw
@b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> Bool
def outcome.io source · line 236 · raw
@+idem:Bool -> @v:Verdict -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)
The wall clock dates a Retry-After, so it is read only for Again.
def jitter.io source · line 250 · raw
@need:Bool -> IO(Nat)
Jitter for the backoff, drawn only when a retry may follow.
def settle.at source · line 259 · 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:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @pool:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @jar:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @r:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R> -> Step<R>
def settle.outcome source · line 264 · raw
@-R:Type -> @+p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @+n:Nat -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @+br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @pool:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @jar:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @r:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R> -> IO(Step<R>)
The attempt has ended: tell the breaker, and plan the next step.
def settle.judged source · line 271 · raw
@-R:Type -> @+p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @+idem:Bool -> @+n:Nat -> @br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @pool:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @jar:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @j:Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R>, Verdict) -> IO(Step<R>)
def judge.status source · line 279 · raw
@+s:U32 -> Verdict
A status that Pure.retry.judge does not retry: below 400 is Ok, a 4xx is Caller, and the rest is Target.
def judge.settled source · line 282 · raw
@r:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res> -> Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>, Verdict)
def judge.of source · line 290 · raw
@x:Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>, Maybe<&2, String>) -> Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>, Verdict)
def judge source · line 299 · raw
@r:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res> -> Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>, Verdict)
The default judge: Pure.retry.judge, as if the request were idempotent, picks Again; outcome then applies idem.
def try.res source · line 313 · raw
@o:Opts -> @call:Call -> @pool:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @jar:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool, Pair(Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>, Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/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 321 · raw
@o:Opts -> @call:Call -> @pool:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @jar:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool, Pair(Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>, Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/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 331 · raw
@r:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res -> IO(Unit)
def denied source · line 355 · 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 388 · raw
@ms:Nat -> IO(Unit)
def result.of source · line 414 · raw
@-R:Type -> @m:Maybe<&1, Result<&1, &1, Err, R>> -> Result<&1, &1, Err, R>
def request.done source · line 421 · raw
@-R:Type -> @+o:Opts -> @s:Step<R> -> Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, R>))
def attempts source · line 425 · raw
@p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> Nat
def budget source · line 430 · 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 471 · raw
@c:Client -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+method:String -> @url:String -> @headers:Map<&2, List<&2, String>> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>)))
request.as with judge, the idempotency of method, and every coding Http decodes.
def request.drop source · line 477 · raw
@x:Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>)) -> Pair(Client, Result<&1, &1, Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>)
def request.budget source · line 481 · raw
@+method:String -> @url:String -> @headers:Map<&2, List<&2, String>> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @x:Pair(Client, 0x14e48621ef66156b0eb652524b8594d4/retry.Budget) -> IO(Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>)))
def request source · line 491 · raw
@c:Client -> @+method:String -> @url:String -> @headers:Map<&2, List<&2, String>> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(Client, Result<&1, &1, Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/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 498 · raw
@c:Client -> @url:String -> IO(Pair(Client, Result<&1, &1, Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>))
def post.json source · line 502 · raw
@c:Client -> @url:String -> @v:0x419ec39802735c4664960ab4b9d962e5/json.Val -> IO(Pair(Client, Result<&1, &1, Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>))
POST v as compact JSON, with content-type: application/json.
Templates
template settle source · line 302 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R> -> Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R>, Verdict)) -> @+p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @+idem:Bool -> @+n:Nat -> @br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @x:Pair(0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool, Pair(Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>, Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R>)) -> IO(Step<R>)
template close.last source · line 334 · raw
@-R:Type -> @-close:(@_:R -> IO(Unit)) -> @last:Maybe<&1, Result<&1, &1, Err, R>> -> IO(Unit)
template attempt.run source · line 345 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R> -> Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R>, Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @_:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool, Pair(Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>, Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R>)))) -> @+o:Opts -> @+call:Call -> @+idem:Bool -> @+n:Nat -> @pool:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @jar:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> IO(Step<R>)
template attempt.gate source · line 363 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R> -> Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R>, Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @_:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool, Pair(Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>, Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/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:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @jar:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @body:0xec25e4adfb02e59e4b817801115988ee/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 379 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R> -> Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R>, Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @_:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool, Pair(Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>, Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/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 396 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R> -> Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R>, Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @_:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool, Pair(Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>, Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/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 437 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R> -> Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, R>, Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool -> @_:Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar> -> @_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Pool, Pair(Maybe<&2, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Jar>, Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/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:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, R>)))
template request.as source · line 455 · raw
@-judge:(@_:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res> -> Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Res>, Verdict)) -> @c:Client -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+idem:Bool -> @+enc:String -> @+method:String -> @url:String -> @headers:Map<&2, List<&2, String>> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/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; Hairpin.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 465 · raw
@-judge:(@_:Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Stream> -> Pair(Result<&1, &1, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/pure.Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/http.Stream>, Verdict)) -> @c:Client -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+idem:Bool -> @+enc:String -> @+method:String -> @url:String -> @headers:Map<&2, List<&2, String>> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, 0xaba1cd8e58dfba7b7b1fa48aa885aa3b/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.