RequestInterceptor
public protocol RequestInterceptor : RequestAdapter, RequestRetrier
Type that provides both RequestAdapter
and RequestRetrier
functionality.
-
adapt(_:
Extension methodfor: completion: ) Declaration
Swift
@preconcurrency public func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping @Sendable (Result<URLRequest, any Error>) -> Void)
-
retry(_:
Extension methodfor: dueTo: completion: ) Declaration
Swift
@preconcurrency public func retry(_ request: Request, for session: Session, dueTo error: any Error, completion: @escaping @Sendable (RetryResult) -> Void)
-
deflateCompressor
Extension methodCreate a
DeflateRequestCompressor
with defaultduplicateHeaderBehavior
andshouldCompressBodyData
values.Declaration
Swift
public static var deflateCompressor: DeflateRequestCompressor { get }
-
deflateCompressor(duplicateHeaderBehavior:
Extension methodshouldCompressBodyData: ) Creates a
DeflateRequestCompressor
with the providedDuplicateHeaderBehavior
andshouldCompressBodyData
closure.Declaration
Swift
public static func deflateCompressor( duplicateHeaderBehavior: DeflateRequestCompressor.DuplicateHeaderBehavior = .error, shouldCompressBodyData: @escaping @Sendable (_ bodyData: Data) -> Bool = { _ in true } ) -> DeflateRequestCompressor
Parameters
duplicateHeaderBehavior
DuplicateHeaderBehavior
to use.shouldCompressBodyData
Closure which determines whether the outgoing body data should be compressed.
true
by default.Return Value
-
interceptor(adapter:
Extension methodretrier: ) Creates an
Interceptor
using the providedAdaptHandler
andRetryHandler
closures.Declaration
Swift
@preconcurrency public static func interceptor(adapter: @escaping AdaptHandler, retrier: @escaping RetryHandler) -> Interceptor
Parameters
adapter
AdapterHandler
to use to adapt the request.retrier
RetryHandler
to use to retry the request.Return Value
The
Interceptor
. -
interceptor(adapter:
Extension methodretrier: ) Creates an
Interceptor
using the providedRequestAdapter
andRequestRetrier
instances.Declaration
Swift
@preconcurrency public static func interceptor(adapter: any RequestAdapter, retrier: any RequestRetrier) -> Interceptor
Parameters
adapter
RequestAdapter
to use to adapt the requestretrier
RequestRetrier
to use to retry the request.Return Value
The
Interceptor
. -
interceptor(adapters:
Extension methodretriers: interceptors: ) Creates an
Interceptor
using the providedRequestAdapter
s,RequestRetrier
s, andRequestInterceptor
s.Declaration
Swift
@preconcurrency public static func interceptor(adapters: [any RequestAdapter] = [], retriers: [any RequestRetrier] = [], interceptors: [any RequestInterceptor] = []) -> Interceptor
Parameters
adapters
RequestAdapter
s to use to adapt the request. These adapters will be run until one fails.retriers
RequestRetrier
s to use to retry the request. These retriers will be run one at a time until a retry is triggered.interceptors
RequestInterceptor
s to use to intercept the request.Return Value
The
Interceptor
.
-
retryPolicy
Extension methodProvides a default
RetryPolicy
instance.Declaration
Swift
public static var retryPolicy: RetryPolicy { get }
-
retryPolicy(retryLimit:
Extension methodexponentialBackoffBase: exponentialBackoffScale: retryableHTTPMethods: retryableHTTPStatusCodes: retryableURLErrorCodes: ) Creates an
RetryPolicy
from the specified parameters.Declaration
Swift
public static func retryPolicy(retryLimit: UInt = RetryPolicy.defaultRetryLimit, exponentialBackoffBase: UInt = RetryPolicy.defaultExponentialBackoffBase, exponentialBackoffScale: Double = RetryPolicy.defaultExponentialBackoffScale, retryableHTTPMethods: Set<HTTPMethod> = RetryPolicy.defaultRetryableHTTPMethods, retryableHTTPStatusCodes: Set<Int> = RetryPolicy.defaultRetryableHTTPStatusCodes, retryableURLErrorCodes: Set<URLError.Code> = RetryPolicy.defaultRetryableURLErrorCodes) -> RetryPolicy
Parameters
retryLimit
The total number of times the request is allowed to be retried.
2
by default.exponentialBackoffBase
The base of the exponential backoff policy.
2
by default.exponentialBackoffScale
The scale of the exponential backoff.
0.5
by default.retryableHTTPMethods
The HTTP methods that are allowed to be retried.
RetryPolicy.defaultRetryableHTTPMethods
by default.retryableHTTPStatusCodes
The HTTP status codes that are automatically retried by the policy.
RetryPolicy.defaultRetryableHTTPStatusCodes
by default.retryableURLErrorCodes
The URL error codes that are automatically retried by the policy.
RetryPolicy.defaultRetryableURLErrorCodes
by default.Return Value
The
RetryPolicy
-
connectionLostRetryPolicy
Extension methodProvides a default
ConnectionLostRetryPolicy
instance.Declaration
Swift
public static var connectionLostRetryPolicy: ConnectionLostRetryPolicy { get }
-
connectionLostRetryPolicy(retryLimit:
Extension methodexponentialBackoffBase: exponentialBackoffScale: retryableHTTPMethods: ) Creates a
ConnectionLostRetryPolicy
instance from the specified parameters.Declaration
Swift
public static func connectionLostRetryPolicy(retryLimit: UInt = RetryPolicy.defaultRetryLimit, exponentialBackoffBase: UInt = RetryPolicy.defaultExponentialBackoffBase, exponentialBackoffScale: Double = RetryPolicy.defaultExponentialBackoffScale, retryableHTTPMethods: Set<HTTPMethod> = RetryPolicy.defaultRetryableHTTPMethods) -> ConnectionLostRetryPolicy
Parameters
retryLimit
The total number of times the request is allowed to be retried.
RetryPolicy.defaultRetryLimit
by default.exponentialBackoffBase
The base of the exponential backoff policy.
RetryPolicy.defaultExponentialBackoffBase
by default.exponentialBackoffScale
The scale of the exponential backoff.
RetryPolicy.defaultExponentialBackoffScale
by default.retryableHTTPMethods
The idempotent http methods to retry.
Return Value