Compression

public class Compression : RouterMiddleware

A middleware for compressing body data sent back to the client. Supports the deflate and the gzip compression methods. Uses zlib.

  • The byte count threshold for the response body size before compression is considered for the response. For more information, see zlib manual.

    Declaration

    Swift

    public var threshold: Int
  • The size of the internal output slab buffer in bytes. For more information, see zlib manual.

    Declaration

    Swift

    public var chunkSize: Int
  • The level of zlib compression to apply. For more information, see zlib manual.

    Declaration

    Swift

    public var compressionLevel: CompressionLevel
  • The strategy of zlib compression to apply. For more information, see zlib manual.

    Declaration

    Swift

    public var compressionStrategy: CompressionStrategy
  • The level of the compression memory, used to specify how much memory should be allocated for the internal compression state. For more information, see zlib manual.

    Declaration

    Swift

    public var memoryLevel: Int32
  • Initialize an instance of Compression.

    Declaration

    Swift

    public init(threshold: Int = 1024, chunkSize: Int = 65536, compressionLevel: CompressionLevel = CompressionLevel.defaultCompression, compressionStrategy: CompressionStrategy = CompressionStrategy.defaultStrategy, memoryLevel: Int32 = 8)

    Parameters

    threshold

    The byte count threshold for the response body size.

    chunkSize

    The size of the internal output slab buffer in bytes.

    compressionLevel

    The level of zlib compression to apply.

    compressionStrategy

    The strategy of zlib compression to apply.

    memoryLevel

    The level of the memory to be allocated during the compression.

  • Handle an incoming request, compressing the body of the response, if applicable.

    Throws

    Any ErrorType. If an error is thrown, processing of the request is stopped, the error handlers, if any are defined, will be invoked, and the user will get a response with a status code of 500.

    Declaration

    Swift

    public func handle(request: RouterRequest, response: RouterResponse, next: @escaping () -> Void) throws

    Parameters

    request

    The RouterRequest object used to get information about the request.

    response

    The RouterResponse object used to respond to the request.

    next

    The closure to invoke to enable the Router to check for other handlers or middleware to work with this request.