docs/Protocols/RequestInterceptor.html
public protocol RequestInterceptor : RequestAdapter, RequestRetrier
Type that provides both RequestAdapter and RequestRetrier functionality.
`
adapt(_:for:completion:)
` Extension method
Swift
@preconcurrency
public func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping @Sendable (Result<URLRequest, any Error>) -> Void)
`
retry(_:for:dueTo:completion:)
` Extension method
Swift
@preconcurrency
public func retry(_ request: Request,
for session: Session,
dueTo error: any Error,
completion: @escaping @Sendable (RetryResult) -> Void)
Self == OfflineRetrier`
offlineRetrier(monitor:maximumWait:isOfflineError:)
` Extension method
Creates an instance from the provided NWPathMonitor, maximum wait for connectivity, and offline error predicate.
Swift
public static func offlineRetrier(
monitor: @autoclosure @escaping () -> NWPathMonitor = NWPathMonitor(),
maximumWait: DispatchTimeInterval = OfflineRetrier.defaultWait,
isOfflineError: @escaping @Sendable (_ error: any Error) -> Bool = OfflineRetrier.defaultIsOfflineError
) -> OfflineRetrier
| monitor |
NWPathMonitor() to use to detect connectivity. A new instance is created each time a request fails and retry may be needed.
|
| maximumWait |
DispatchTimeInterval to wait for connectivity before timeout.
|
| isOfflineError |
Predicate closure used to determine whether a paricular any Error indicates connectivity is offline. Returning false moves to the next retrier, if any.
|
`
offlineRetrier(requiredInterfaceType:maximumWait:isOfflineError:)
` Extension method
Creates an instance using an NWPathMonitor configured with the provided InterfaceType, maximum wait for connectivity, and offline error predicate.
Swift
public static func offlineRetrier(
requiredInterfaceType: NWInterface.InterfaceType,
maximumWait: DispatchTimeInterval = OfflineRetrier.defaultWait,
isOfflineError: @escaping @Sendable (_ error: any Error) -> Bool = OfflineRetrier.defaultIsOfflineError
) -> OfflineRetrier
| monitor |
NWInterface.InterfaceType used to configured the NWPathMonitor each time one is needed.
|
| maximumWait |
DispatchTimeInterval to wait for connectivity before timeout.
|
| isOfflineError |
Predicate closure used to determine whether a paricular any Error indicates connectivity is offline. Returning false moves to the next retrier, if any.
|
`
offlineRetrier(prohibitedInterfaceTypes:maximumWait:isOfflineError:)
` Extension method
Creates an instance using an NWPathMonitor configured with the provided InterfaceTypes, maximum wait for connectivity, and offline error predicate.
Swift
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, visionOS 1, *)
public static func offlineRetrier(
prohibitedInterfaceTypes: [NWInterface.InterfaceType],
maximumWait: DispatchTimeInterval = OfflineRetrier.defaultWait,
isOfflineError: @escaping @Sendable (_ error: any Error) -> Bool = OfflineRetrier.defaultIsOfflineError
) -> OfflineRetrier
| monitor |
[NWInterface.InterfaceType] used to configured the NWPathMonitor each time one is needed.
|
| maximumWait |
DispatchTimeInterval to wait for connectivity before timeout.
|
| isOfflineError |
Predicate closure used to determine whether a paricular any Error indicates connectivity is offline. Returning false moves to the next retrier, if any.
|
Self == DeflateRequestCompressor`
deflateCompressor
` Extension method
Create a DeflateRequestCompressor with default duplicateHeaderBehavior and shouldCompressBodyData values.
Swift
public static var deflateCompressor: DeflateRequestCompressor { get }
`
deflateCompressor(duplicateHeaderBehavior:shouldCompressBodyData:)
` Extension method
Creates a DeflateRequestCompressor with the provided DuplicateHeaderBehavior and shouldCompressBodyData closure.
Swift
public static func deflateCompressor(
duplicateHeaderBehavior: DeflateRequestCompressor.DuplicateHeaderBehavior = .error,
shouldCompressBodyData: @escaping @Sendable (_ bodyData: Data) -> Bool = { _ in true }
) -> DeflateRequestCompressor
| duplicateHeaderBehavior |
DuplicateHeaderBehavior to use.
|
| shouldCompressBodyData |
Closure which determines whether the outgoing body data should be compressed. true by default.
|
The DeflateRequestCompressor.
Self == Interceptor`
interceptor(adapter:retrier:)
` Extension method
Creates an Interceptor using the provided AdaptHandler and RetryHandler closures.
Swift
@preconcurrency
public static func interceptor(adapter: @escaping AdaptHandler, retrier: @escaping RetryHandler) -> Interceptor
| adapter |
AdapterHandlerto use to adapt the request.
|
| retrier |
RetryHandler to use to retry the request.
|
The Interceptor.
`
interceptor(adapter:retrier:)
` Extension method
Creates an Interceptor using the provided RequestAdapter and RequestRetrier instances.
Swift
@preconcurrency
public static func interceptor(adapter: any RequestAdapter, retrier: any RequestRetrier) -> Interceptor
| adapter |
RequestAdapter to use to adapt the request
|
| retrier |
RequestRetrier to use to retry the request.
|
The Interceptor.
`
interceptor(adapters:retriers:interceptors:)
` Extension method
Creates an Interceptor using the provided RequestAdapters, RequestRetriers, and RequestInterceptors.
Swift
@preconcurrency
public static func interceptor(adapters: [any RequestAdapter] = [],
retriers: [any RequestRetrier] = [],
interceptors: [any RequestInterceptor] = []) -> Interceptor
| adapters |
RequestAdapters to use to adapt the request. These adapters will be run until one fails.
|
| retriers |
RequestRetriers to use to retry the request. These retriers will be run one at a time until a retry is triggered.
|
| interceptors |
RequestInterceptors to use to intercept the request.
|
The Interceptor.
Self == RetryPolicy`
retryPolicy
` Extension method
Provides a default RetryPolicy instance.
Swift
public static var retryPolicy: RetryPolicy { get }
`
retryPolicy(retryLimit:exponentialBackoffBase:exponentialBackoffScale:retryableHTTPMethods:retryableHTTPStatusCodes:retryableURLErrorCodes:)
` Extension method
Creates an RetryPolicy from the specified parameters.
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
| 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.
|
The RetryPolicy
Self == ConnectionLostRetryPolicy`
connectionLostRetryPolicy
` Extension method
Provides a default ConnectionLostRetryPolicy instance.
Swift
public static var connectionLostRetryPolicy: ConnectionLostRetryPolicy { get }
`
connectionLostRetryPolicy(retryLimit:exponentialBackoffBase:exponentialBackoffScale:retryableHTTPMethods:)
` Extension method
Creates a ConnectionLostRetryPolicy instance from the specified parameters.
Swift
public static func connectionLostRetryPolicy(retryLimit: UInt = RetryPolicy.defaultRetryLimit,
exponentialBackoffBase: UInt = RetryPolicy.defaultExponentialBackoffBase,
exponentialBackoffScale: Double = RetryPolicy.defaultExponentialBackoffScale,
retryableHTTPMethods: Set<HTTPMethod> = RetryPolicy.defaultRetryableHTTPMethods) -> ConnectionLostRetryPolicy
| 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.
|
The ConnectionLostRetryPolicy.