Skip to content

Instance Method

responseCompression(_:force:)

Override the response compression settings for a route.
func responseCompression(_ override: HTTPHeaders.ResponseCompression, force shouldForce: Bool = false) -> any RoutesBuilder

Parameters

override

The compression preference to apply if none is already set.

shouldForce

Wether to force the compression preference over what the response prefers.

Return Value

A route with the specified response compression preferences.

Discussion

This is useful when a set of static routes does not need compression, or a set of dynamic routes does.

When the HTTPServer.Configuration.ResponseCompressionConfiguration is set to be disabled by default, HTTPHeaders/ResponseCompression/enable can be set to explicitly enable compression. Likewise, when the configuration is set to be enabled by default, HTTPHeaders/ResponseCompression/disable can be set to explicitly disable compression.

To ignore a preference a downstream middleware (ie. closer to the root route than to the original response) may propose in favor of the server defaults, use HTTPHeaders/ResponseCompression/useDefault.

Note

Response compression is only actually used if the client indicates it supports it via an Accept header.

Note

Setting the override to HTTPHeaders/ResponseCompression/unset has no effect here unless force is set to true.