URLRequestInterceptor

public protocol URLRequestInterceptor

A URLRequestInterceptor accepts a request and returns a request. It is invoked during the “prepare” phase of an API operation.

A URLRequestInterceptor may use the request as a data source for some other operation (e.g., metrics or logging), or use it as the source for preparing a new request that will be used to fulfill the operation. For example, a URLRequestInterceptor may add custom headers to the request for authorization.

URLRequestInterceptors are invoked in the order in which they are added to the plugin.

  • intercept(_:) Asynchronous

    Inspect and optionally modify the request, returning either the original unmodified request or a modified copy.

    Declaration

    Swift

    func intercept(_ request: URLRequest) async throws -> URLRequest

    Parameters

    request

    The URLRequest