Scoop API

scoop:scoop.http.client:0.1.0

src/retry/plan.scoop

Selected production source · src/retry/plan.scoop

1package scoop.http.client
3import scoop.http.HttpResponseHead
4import scoop.time.Duration
6internal fun planClientResponseFollowUp(call: ClientCall, head: HttpResponseHead): ClientFollowUp? {
7 val sequence = call.sequence
8 val redirect = planClientRedirect(call.originalRequest, head, sequence.redirects, sequence.history, clientPresent(sequence.webSocket))
9 if (clientPresent(redirect)) return Some(ClientFollowUp.Redirect(redirect!!))
10 val target = if (head.status == 407U && clientUsesForwardProxy(call)) call.proxyAuthentication!! else call.authentication
11 val authentication = planClientAuthentication(call, head, target)
12 if (clientPresent(authentication)) return Some(ClientFollowUp.Authenticate(authentication!!))
13 val options = sequence.retries
14 if (sequence.retryCount >= options.maxRetries || !call.request.body.isReplayable ||
15 !clientRetryMethod(options, call.request.method)) return None
16 for (status in options.statuses) {
17 if (head.status == status) return Some(ClientFollowUp.Retry(clientRetryDelay(options, sequence.retryCount, Some(head))))
18 }
19 return None
22internal fun planClientFailureRetry(sequence: ClientRequestSequence, request: HttpRequest,
23 failure: ClientIoFailure, bodyStarted: Boolean): Duration? {
24 val options = sequence.retries
25 if (!options.connectionFailures || sequence.retryCount >= options.maxRetries) return None
26 val allowed = clientRetryMethod(options, request.method)
27 when (failure.reason) {
28 case Connection -> if (!allowed || !request.body.isReplayable) return None
29 case NotProcessed -> {
30 if (bodyStarted && !request.body.isReplayable) return None
31 if (!allowed) {
32 if (sequence.unprocessedRetryUsed) return None
33 sequence.unprocessedRetryUsed = true
34 }
35 }
36 }
37 return Some(clientRetryDelay(options, sequence.retryCount))
40private fun clientRetryMethod(options: HttpRetryOptions, method: String): Boolean {
41 for (candidate in options.methods) if (candidate == method) return true
42 return false