Scoop API

scoop:scoop.http.client:0.1.0

src/retry/options.scoop

Selected production source · src/retry/options.scoop

1package scoop.http.client
3import scoop.collections.emptyList
4import scoop.http.isHttpToken
5import scoop.time.Duration
7/**
8 * Bounded retry eligibility and cancellable backoff. Both method semantics and body replayability
9 * must permit another attempt.
10 */
11public class HttpRetryOptions internal constructor(
12 /**
13 * Maximum retries after the initial attempt.
14 */
15 public val maxRetries: Long = 2L,
16 /**
17 * Whether eligible connection failures may trigger retry.
18 */
19 public val connectionFailures: Boolean = true,
20 methods: List<String> = ["GET", "HEAD", "PUT", "DELETE", "OPTIONS", "TRACE"],
21 statuses: List<UInt> = emptyList<UInt>(),
22 /**
23 * The initial backoff delay.
24 */
25 public val initialDelay: Duration = Duration.milliseconds(100L),
26 /**
27 * The maximum selected backoff delay.
28 */
29 public val maxDelay: Duration = Duration.seconds(30L),
30 /**
31 * Whether retry delays are randomized within the backoff policy.
32 */
33 public val jitter: Boolean = true,
34 /**
35 * Whether a valid Retry-After response participates in delay selection.
36 */
37 public val respectRetryAfter: Boolean = true
38) {
39 /**
40 * Case-sensitive methods eligible for configured retries.
41 */
42 public val methods: Array<String> = methods.toArray()
43 /**
44 * Response statuses explicitly eligible for retry.
45 */
46 public val statuses: Array<UInt> = statuses.toArray()
47 init {
48 if (maxRetries < 0L)
49 throw IllegalArgumentException(Some("negative HTTP retry count"))
50 if (initialDelay < Duration.ZERO || maxDelay < initialDelay)
51 throw IllegalArgumentException(Some("invalid HTTP retry delay range"))
52 for (method in this.methods) {
53 if (!isHttpToken(method.toByteArray()))
54 throw IllegalArgumentException(Some("invalid HTTP retry method"))
55 }
56 for (status in this.statuses) {
57 if (status < 200U || status > 599U)
58 throw IllegalArgumentException(Some("invalid HTTP retry status"))
59 }
60 }