Interceptor
public protocol Interceptor
Modifies URLRequests going out and the corresponding URLResponse coming back in.
Usage e.g. for manipulating header field of an existing request.
-
Intercept the chain (e.g. modify it’s request)
Note
A call tochain.proceed(request:)is critical when implementing this protocol function.Declaration
Swift
@available(*, deprecated, message: "Use async version instead") func interceptPublisher(chain: Chain) -> AnyPublisher<HTTPResponse, HTTPClientError>Parameters
chainrequest chain to be intercepted
Return Value
AnyPublisherthat emits the response asHTTPClient.Response -
interceptAsync(chain:Asynchronous) Intercept the chain (e.g. modify it’s request)
Note
A call tochain.proceed(request:)is critical when implementing this protocol function.Note
OnlyHTTPClientErrorare supposed to be thrown.Declaration
Swift
func interceptAsync(chain: Chain) async throws -> HTTPResponseParameters
chainrequest chain to be intercepted
Return Value
Response emitted as
HTTPClient.Response -
intercept(chain:Extension method) Intercept the chain (e.g. modify it’s request)
Note
A call tochain.proceed(request:)is critical when implementing this protocol function.Declaration
Swift
@available(*, deprecated, renamed: "interceptPublisher(chain:﹚", message: "Use async version instead") public func intercept(chain: Chain) -> AnyPublisher<HTTPResponse, HTTPClientError>Parameters
chainrequest chain to be intercepted
Return Value
AnyPublisherthat emits the response asHTTPClient.Response
View on GitHub
Interceptor Protocol Reference