Back to Alamofire

DeflateRequestCompressor

docs/docsets/Alamofire.docset/Contents/Resources/Documents/Structs/DeflateRequestCompressor.html

5.12.03.0 KB
Original Source

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 dedicated requestQueue in your Session instance. Finally, not all servers support request compression, so test with all of your server configurations before deploying.

`

                DuplicateHeaderBehavior
                `

Type that determines the action taken when the URLRequest already has a Content-Encoding header.

See more

Declaration

Swift

public enum DuplicateHeaderBehavior : Sendable

`

                DuplicateHeaderError
                `

Error produced when the outgoing URLRequest already has a Content-Encoding header, when the instance has been configured to produce an error.

Declaration

Swift

public struct DuplicateHeaderError : Error

`

                duplicateHeaderBehavior
                `

Behavior to use when the outgoing URLRequest already has a Content-Encoding header.

Declaration

Swift

public let duplicateHeaderBehavior: DuplicateHeaderBehavior

`

                shouldCompressBodyData
                `

Closure which determines whether the outgoing body data should be compressed.

Declaration

Swift

public let shouldCompressBodyData: @Sendable (_ bodyData: Data) -> Bool

`

                init(duplicateHeaderBehavior:shouldCompressBodyData:)
                `

Creates an instance with the provided parameters.

Declaration

Swift

public init(duplicateHeaderBehavior: DuplicateHeaderBehavior = .error,
            shouldCompressBodyData: @escaping @Sendable (_ bodyData: Data) -> Bool = { _ in true })

Parameters

| duplicateHeaderBehavior |

DuplicateHeaderBehavior to use. .error by default.

| | shouldCompressBodyData |

Closure which determines whether the outgoing body data should be compressed. true by default.

|

`

                adapt(_:for:completion:)
                `

Declaration

Swift

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