Taxum / @taxum/core / middleware/compression / ResponseCompressionLayer
Class: ResponseCompressionLayer
Defined in: middleware/compression.ts:46
A layer that compresses response bodies.
This uses the Accept-Encoding
header to pick an appropriate encoding and adds the Content-Encoding
header to responses.
Example
import { ResponseCompressionLayer } from "@taxum/core/middleware/compression";
import { m, Router } from "@taxum/core/routing";
const router = new Router()
.route("/", m.get(() => "Hello World))
.layer(new ResponseCompressionLayer());
Implements
Constructors
Constructor
new ResponseCompressionLayer():
ResponseCompressionLayer
Defined in: middleware/compression.ts:59
Creates a new ResponseCompressionLayer.
By default, all encodings are accepted and the default compression level is used.
Returns
ResponseCompressionLayer
See
Methods
br()
br(
enable
):this
Defined in: middleware/compression.ts:84
Sets whether to support Brotli encoding.
Parameters
enable
boolean
Returns
this
compressWhen()
compressWhen(
predicate
):this
Defined in: middleware/compression.ts:144
Replace the current compression predicate.
Predicates are used to determine whether a response should be compressed or not. The default predicate is DEFAULT_PREDICATE. See its documentation for more details on which responses it won't compress.
Responses that are already compressed (i.e., have a content-encoding
header) will never be recompressed, regardless of what the predicate says.
Parameters
predicate
Returns
this
deflate()
deflate(
enable
):this
Defined in: middleware/compression.ts:76
Sets whether to support Deflate encoding.
Parameters
enable
boolean
Returns
this
gzip()
gzip(
enable
):this
Defined in: middleware/compression.ts:68
Sets whether to support gzip encoding.
Parameters
enable
boolean
Returns
this
layer()
layer(
inner
):HttpService
Defined in: middleware/compression.ts:149
Wrap the given service with the middleware, returning a new service that has been decorated with the middleware.
Parameters
inner
Returns
Implementation of
noBr()
noBr():
this
Defined in: middleware/compression.ts:122
Disables support for Brotli encoding.
Returns
this
noDeflate()
noDeflate():
this
Defined in: middleware/compression.ts:115
Disables support for Deflate encoding.
Returns
this
noGzip()
noGzip():
this
Defined in: middleware/compression.ts:108
Disabled support for gzip encoding.
Returns
this
noZstd()
noZstd():
this
Defined in: middleware/compression.ts:129
Disables support for Zstd encoding.
Returns
this
quality()
quality(
level
):this
Defined in: middleware/compression.ts:100
Sets the compression quality.
Parameters
level
Returns
this
zstd()
zstd(
enable
):this
Defined in: middleware/compression.ts:92
Sets whether to support Zstd encoding.
Parameters
enable
boolean
Returns
this