RequestInterceptor

public protocol RequestInterceptor : RequestAdapter, RequestRetrier

Type that provides both RequestAdapter and RequestRetrier functionality.

  • adapt(_:for:completion:) Extension method

    Declaration

    Swift

    @preconcurrency
    public func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping @Sendable (Result<URLRequest, any Error>) -> Void)
  • Declaration

    Swift

    @preconcurrency
    public func retry(_ request: Request,
                      for session: Session,
                      dueTo error: any Error,
                      completion: @escaping @Sendable (RetryResult) -> Void)

Available where Self == OfflineRetrier

  • Creates an instance from the provided NWPathMonitor, maximum wait for connectivity, and offline error predicate.

    Declaration

    Swift

    public static func offlineRetrier(
        monitor: @autoclosure @escaping () -> NWPathMonitor = NWPathMonitor(),
        maximumWait: DispatchTimeInterval = OfflineRetrier.defaultWait,
        isOfflineError: @escaping @Sendable (_ error: any Error) -> Bool = OfflineRetrier.defaultIsOfflineError
    ) -> OfflineRetrier

    Parameters

    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.

  • Creates an instance using an NWPathMonitor configured with the provided InterfaceType, maximum wait for connectivity, and offline error predicate.

    Declaration

    Swift

    public static func offlineRetrier(
        requiredInterfaceType: NWInterface.InterfaceType,
        maximumWait: DispatchTimeInterval = OfflineRetrier.defaultWait,
        isOfflineError: @escaping @Sendable (_ error: any Error) -> Bool = OfflineRetrier.defaultIsOfflineError
    ) -> OfflineRetrier

    Parameters

    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.

  • Creates an instance using an NWPathMonitor configured with the provided InterfaceTypes, maximum wait for connectivity, and offline error predicate.

    Declaration

    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

    Parameters

    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.

Available where Self == DeflateRequestCompressor

Available where Self == Interceptor

Available where Self == RetryPolicy

Available where Self == ConnectionLostRetryPolicy