DeflateRequestCompressor
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public struct DeflateRequestCompressor : Sendable, RequestInterceptor
RequestAdapter which compresses outgoing URLRequest bodies using the deflate Content-Encoding and adds the
appropriate header.
Note
Most requests to most APIs are small and so would only be slowed down by applying this adapter. Measure the size of your request bodies and the performance impact of using this adapter before use. Using this adapter with already compressed data, such as images, will, at best, have no effect. Additionally, body compression is a synchronous operation, so measuring the performance impact may be important to determine whether you want to use a dedicatedrequestQueue in your Session instance. Finally, not all servers support request
compression, so test with all of your server configurations before deploying.
-
Type that determines the action taken when the
See moreURLRequestalready has aContent-Encodingheader.Declaration
Swift
public enum DuplicateHeaderBehavior : Sendable -
Errorproduced when the outgoingURLRequestalready has aContent-Encodingheader, when the instance has been configured to produce an error.Declaration
Swift
public struct DuplicateHeaderError : Error -
Behavior to use when the outgoing
URLRequestalready has aContent-Encodingheader.Declaration
Swift
public let duplicateHeaderBehavior: DuplicateHeaderBehavior -
Closure which determines whether the outgoing body data should be compressed.
Declaration
Swift
public let shouldCompressBodyData: @Sendable (_ bodyData: Data) -> Bool -
Creates an instance with the provided parameters.
Declaration
Swift
public init(duplicateHeaderBehavior: DuplicateHeaderBehavior = .error, shouldCompressBodyData: @escaping @Sendable (_ bodyData: Data) -> Bool = { _ in true })Parameters
duplicateHeaderBehaviorDuplicateHeaderBehaviorto use..errorby default.shouldCompressBodyDataClosure which determines whether the outgoing body data should be compressed.
trueby default. -
Declaration
Swift
public func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result<URLRequest, any Error>) -> Void)
View on GitHub
Install in Dash