RealHTTP
RealHTTP copied to clipboard
[#79] Draft: Add custom retry strategy implementation
Hello,
this PR should add the feature requested in #79.
You can provide a custom retry strategy by implementing a closure that takes the current HTTPRequest as input and returns an amount of seconds of your choice.
For example, the requested .exponential(base: 2, from: 1) could be easily implemented in this way:
let strategy: HTTPRetryStrategy = .custom { request in
let numberOfPreviousAttempts = request.currentRetry
let maximumNumberOfAttempts = request.maxRetries
guard numberOfPreviousAttempts < maximumNumberOfAttempts else { return 0 }
return pow(Double(2), Double(numberOfPreviousAttempts + 1))
}
Closes #79