Skip to content

Commit b988f2a

Browse files
authored
🤖 Merge PR DefinitelyTyped#72755 feat(compression): add brotli options and enforceEncoding support by @bjohansebas
Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>
1 parent 5611643 commit b988f2a

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

‎types/compression/compression-tests.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ app.use(
2020
flush: zlib.constants.Z_NO_FLUSH,
2121
finishFlush: zlib.constants.Z_FINISH,
2222
dictionary: Buffer.from("Hello World!"),
23+
// brotli options
24+
brotli: {
25+
params: {
26+
[zlib.constants.BROTLI_PARAM_QUALITY]: 4,
27+
[zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_DEFAULT_MODE,
28+
},
29+
},
2330
info: true,
2431
}),
2532
);
@@ -38,6 +45,8 @@ app.use(
3845
}),
3946
);
4047

48+
app.use(compression({ enforceEncoding: "br" }));
49+
4150
// compression.filter
4251

4352
app.use(compression({ filter: shouldCompress }));

‎types/compression/index.d.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import express = require("express");
2+
import * as zlib from "zlib";
23

34
// This module adds a res.flush() method to force the partially-compressed response to be flushed to the client.
45

@@ -81,6 +82,17 @@ declare namespace compression {
8182
*/
8283
filter?: CompressionFilter | undefined;
8384

85+
/**
86+
* Options for brotli compression.
87+
*/
88+
brotli?: zlib.BrotliOptions | undefined;
89+
90+
/**
91+
* This is the default encoding to use when the client does not specify an encoding in the request's Accept-Encoding header.
92+
* @default 'identity'
93+
*/
94+
enforceEncoding?: string | undefined;
95+
8496
/**
8597
* The level of zlib compression to apply to responses. A higher level will result in better compression, but
8698
* will take longer to complete. A lower level will result in less compression, but will be much faster.

‎types/compression/package.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"private": true,
33
"name": "@types/compression",
4-
"version": "1.7.9999",
4+
"version": "1.8.9999",
55
"projects": [
66
"https://github.com/expressjs/compression"
77
],
88
"dependencies": {
9-
"@types/express": "*"
9+
"@types/express": "*",
10+
"@types/node": "*"
1011
},
1112
"devDependencies": {
12-
"@types/compression": "workspace:.",
13-
"@types/node": "*"
13+
"@types/compression": "workspace:."
1414
},
1515
"owners": [
1616
{

0 commit comments

Comments
 (0)