scoop:scoop.http.client:0.1.0
src/retry/plan.scoop
Selected production source · src/retry/plan.scoop
1
package scoop.http.client3
import scoop.http.HttpResponseHead4
import scoop.time.Duration6
internal fun planClientResponseFollowUp(call: ClientCall, head: HttpResponseHead): ClientFollowUp? {7
val sequence = call.sequence8
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.authentication11
val authentication = planClientAuthentication(call, head, target)12
if (clientPresent(authentication)) return Some(ClientFollowUp.Authenticate(authentication!!))13
val options = sequence.retries14
if (sequence.retryCount >= options.maxRetries || !call.request.body.isReplayable ||15
!clientRetryMethod(options, call.request.method)) return None16
for (status in options.statuses) {17
if (head.status == status) return Some(ClientFollowUp.Retry(clientRetryDelay(options, sequence.retryCount, Some(head))))18
}19
return None20
}22
internal fun planClientFailureRetry(sequence: ClientRequestSequence, request: HttpRequest,23
failure: ClientIoFailure, bodyStarted: Boolean): Duration? {24
val options = sequence.retries25
if (!options.connectionFailures || sequence.retryCount >= options.maxRetries) return None26
val allowed = clientRetryMethod(options, request.method)27
when (failure.reason) {28
case Connection -> if (!allowed || !request.body.isReplayable) return None29
case NotProcessed -> {30
if (bodyStarted && !request.body.isReplayable) return None31
if (!allowed) {32
if (sequence.unprocessedRetryUsed) return None33
sequence.unprocessedRetryUsed = true34
}35
}36
}37
return Some(clientRetryDelay(options, sequence.retryCount))38
}40
private fun clientRetryMethod(options: HttpRetryOptions, method: String): Boolean {41
for (candidate in options.methods) if (candidate == method) return true42
return false43
}