hairpin.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-hairpin@0.16.0.0/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
7 imports
import Base import bend-kit-http@0.40.0.0/http.bend as Http import bend-kit-time@0.3.0.1/time.bend as Time 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 12 · 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:0x354b3c2ee5a660bddb313748129f568d/http.Mode -> @policy:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @cert:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Cert> -> @ca:String -> Opts
type Client source · line 16 · raw
Type
breaker: the circuit breaker of every request on this client.
Client@opts:Opts -> @pool:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @jar:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> @breaker:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> Client
type Err source · line 20 · raw
Data
ErrHttp: the last attempt failed. ErrDenied: no attempt started, for why.
ErrHttp@error:0x354b3c2ee5a660bddb313748129f568d/http.Err -> Err
ErrDenied@why:0x14e48621ef66156b0eb652524b8594d4/retry.Deny -> Err
type Verdict source · line 163 · 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 190 · 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:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @jar:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.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 307 · 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 25 · 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 30 · 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 33 · raw
Client
def base source · line 36 · raw
@c:Client -> @url:String -> Client
def header source · line 41 · 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 45 · raw
@c:Client -> @ms:U32 -> Client
def redirect source · line 49 · raw
@c:Client -> @mode:0x354b3c2ee5a660bddb313748129f568d/http.Mode -> Client
def retry source · line 54 · raw
@c:Client -> @n:U32 -> Client
Up to n retries after the first attempt: n + 1 attempts in all.
def deadline source · line 59 · raw
@c:Client -> @ms:U32 -> Client
No attempt of a request starts ms or more after the request starts.
def circuit source · line 64 · raw
@c:Client -> @circ:0x14e48621ef66156b0eb652524b8594d4/retry.Circuit -> Client
A circuit breaker in front of every request, starting closed.
def breaker.of source · line 69 · raw
@c:Client -> Pair(Client, 0x14e48621ef66156b0eb652524b8594d4/retry.Breaker)
The breaker, for inspection.
def cert source · line 74 · 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 79 · 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 84 · raw
@c:Client -> @jar:0x354b3c2ee5a660bddb313748129f568d/http.Jar -> Client
Every request stores and sends cookies through jar. Its clock moves to Time.now() before each try.
def jar.of source · line 89 · raw
@c:Client -> Pair(Client, Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>)
The jar, if the client has one.
def close source · line 93 · raw
@c:Client -> IO(Unit)
def stream.close source · line 98 · raw
@c:Client -> @st:0x354b3c2ee5a660bddb313748129f568d/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 104 · raw
@none:Bool -> @b:String -> @ref:String -> Maybe<&2, String>
def target source · line 112 · 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 115 · raw
@m:Maybe<&2, String> -> Maybe<&2, 0x1f2d80f53f971b16c6de6a65cb1918ae/url.Abs>
def merge source · line 124 · 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 127 · raw
@j:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> IO(Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>)
def once.final source · line 136 · raw
@+enc:String -> @x:Pair(0x354b3c2ee5a660bddb313748129f568d/http.Pool, Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res>, Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>)) -> IO(Pair(0x354b3c2ee5a660bddb313748129f568d/http.Pool, Pair(Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>, Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res>)))
def once source · line 144 · raw
@+ms:U32 -> @+mode:0x354b3c2ee5a660bddb313748129f568d/http.Mode -> @+cert:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Cert> -> @+ca:String -> @+enc:String -> @p:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @j:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> @+method:String -> @+u:Maybe<&2, 0x1f2d80f53f971b16c6de6a65cb1918ae/url.Abs> -> @+headers:Map<&2, List<&2, String>> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0x354b3c2ee5a660bddb313748129f568d/http.Pool, Pair(Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>, Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.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 153 · raw
@m:Maybe<&2, U32> -> Maybe<&2, Nat>
def outcome source · line 170 · raw
@+idem:Bool -> @v:Verdict -> @now:0x0d2a146cd1cbaedf76cc532bcd3594b0/time.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 181 · raw
@-R:Type -> @r:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R> -> Result<&1, &1, Err, R>
def clock source · line 195 · 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 202 · raw
@br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> Bool
def transient source · line 209 · raw
@o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> Bool
def some source · line 222 · raw
@m:Maybe<&2, Nat> -> Bool
def deadline.some source · line 229 · raw
@b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> Bool
def outcome.io source · line 234 · 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 248 · raw
@need:Bool -> IO(Nat)
Jitter for the backoff, drawn only when a retry may follow.
def settle.at source · line 257 · 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:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @jar:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> @r:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R> -> Step<R>
def settle.outcome source · line 262 · 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:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @jar:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> @r:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R> -> IO(Step<R>)
The attempt has ended: tell the breaker, and plan the next step.
def settle.judged source · line 269 · raw
@-R:Type -> @+p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @+idem:Bool -> @+n:Nat -> @br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @pool:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @jar:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> @j:Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R>, Verdict) -> IO(Step<R>)
def judge.status source · line 277 · raw
@+s:U32 -> Verdict
A status that Http.retry.judge does not retry: below 400 is Ok, a 4xx is Caller, and the rest is Target.
def judge.settled source · line 280 · raw
@r:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res> -> Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res>, Verdict)
def judge.of source · line 288 · raw
@x:Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res>, Maybe<&2, String>) -> Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res>, Verdict)
def judge source · line 297 · raw
@r:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res> -> Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res>, Verdict)
The default judge: Http.retry.judge, as if the request were idempotent, picks Again; outcome then applies idem.
def try.res source · line 311 · raw
@o:Opts -> @call:Call -> @pool:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @jar:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0x354b3c2ee5a660bddb313748129f568d/http.Pool, Pair(Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>, Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.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 319 · raw
@o:Opts -> @call:Call -> @pool:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @jar:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0x354b3c2ee5a660bddb313748129f568d/http.Pool, Pair(Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>, Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/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 329 · raw
@r:0x354b3c2ee5a660bddb313748129f568d/http.Res -> IO(Unit)
def denied source · line 353 · 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 386 · raw
@ms:Nat -> IO(Unit)
def result.of source · line 412 · raw
@-R:Type -> @m:Maybe<&1, Result<&1, &1, Err, R>> -> Result<&1, &1, Err, R>
def request.done source · line 419 · raw
@-R:Type -> @+o:Opts -> @s:Step<R> -> Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, R>))
def attempts source · line 423 · raw
@p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> Nat
def budget source · line 428 · 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 469 · 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, 0x354b3c2ee5a660bddb313748129f568d/http.Res>)))
request.as with judge, the idempotency of method, and every coding Http decodes.
def request.drop source · line 475 · raw
@x:Pair(Client, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, Result<&1, &1, Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res>)) -> Pair(Client, Result<&1, &1, Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res>)
def request.budget source · line 479 · 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, 0x354b3c2ee5a660bddb313748129f568d/http.Res>)))
def request source · line 489 · raw
@c:Client -> @+method:String -> @url:String -> @headers:Map<&2, List<&2, String>> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(Client, Result<&1, &1, Err, 0x354b3c2ee5a660bddb313748129f568d/http.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 Http.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 496 · raw
@c:Client -> @url:String -> IO(Pair(Client, Result<&1, &1, Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res>))
def post.json source · line 500 · raw
@c:Client -> @url:String -> @v:0x419ec39802735c4664960ab4b9d962e5/json.Val -> IO(Pair(Client, Result<&1, &1, Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res>))
POST v as compact JSON, with content-type: application/json.
Templates
template settle source · line 300 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R> -> Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.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(0x354b3c2ee5a660bddb313748129f568d/http.Pool, Pair(Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>, Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R>)) -> IO(Step<R>)
template close.last source · line 332 · raw
@-R:Type -> @-close:(@_:R -> IO(Unit)) -> @last:Maybe<&1, Result<&1, &1, Err, R>> -> IO(Unit)
template attempt.run source · line 343 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R> -> Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R>, Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @_:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> @_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0x354b3c2ee5a660bddb313748129f568d/http.Pool, Pair(Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>, Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R>)))) -> @+o:Opts -> @+call:Call -> @+idem:Bool -> @+n:Nat -> @pool:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @jar:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.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 361 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R> -> Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R>, Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @_:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> @_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0x354b3c2ee5a660bddb313748129f568d/http.Pool, Pair(Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>, Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.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:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @jar:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.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 377 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R> -> Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R>, Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @_:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> @_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0x354b3c2ee5a660bddb313748129f568d/http.Pool, Pair(Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>, Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.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 394 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R> -> Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R>, Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @_:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> @_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0x354b3c2ee5a660bddb313748129f568d/http.Pool, Pair(Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>, Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.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 435 · raw
@-R:Type -> @-judge:(@_:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R> -> Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, R>, Verdict)) -> @-try:(@_:Opts -> @_:Call -> @_:0x354b3c2ee5a660bddb313748129f568d/http.Pool -> @_:Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar> -> @_:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> IO(Pair(0x354b3c2ee5a660bddb313748129f568d/http.Pool, Pair(Maybe<&2, 0x354b3c2ee5a660bddb313748129f568d/http.Jar>, Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.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 453 · raw
@-judge:(@_:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.Res> -> Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.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, 0x354b3c2ee5a660bddb313748129f568d/http.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 463 · raw
@-judge:(@_:Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/http.Stream> -> Pair(Result<&1, &1, 0x354b3c2ee5a660bddb313748129f568d/http.Err, 0x354b3c2ee5a660bddb313748129f568d/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, 0x354b3c2ee5a660bddb313748129f568d/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.