koa-compress 5.0.1 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/lib/encodings.js +8 -0
- package/lib/index.js +16 -2
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -27,6 +27,11 @@ app.use(compress({
|
|
|
27
27
|
}))
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
## Maintainers
|
|
31
|
+
|
|
32
|
+
- Lead: @jonathanong [@jongleberry](https://twitter.com/jongleberry)
|
|
33
|
+
- Team: @koajs/compress
|
|
34
|
+
|
|
30
35
|
## Options
|
|
31
36
|
|
|
32
37
|
### filter\<Function\>
|
|
@@ -54,12 +59,13 @@ Setting `options[encoding] = false` will disable that encoding.
|
|
|
54
59
|
#### options<span></span>.br
|
|
55
60
|
|
|
56
61
|
[Brotli compression](https://en.wikipedia.org/wiki/Brotli) is supported in node v11.7.0+, which includes it natively.
|
|
62
|
+
As of v5.1.0, the default quality level is 4 for performance reasons.
|
|
57
63
|
|
|
58
64
|
### options.defaultEncoding\<String\>
|
|
59
65
|
|
|
60
66
|
An optional string, which specifies what encoders to use for requests without
|
|
61
67
|
[Accept-Encoding](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding).
|
|
62
|
-
Default `
|
|
68
|
+
Default `identity`.
|
|
63
69
|
|
|
64
70
|
The standard dictates to treat such requests as `*` meaning that all compressions are permissible,
|
|
65
71
|
yet it causes very practical problems when debugging servers with manual tools like `curl`, `wget`, and so on.
|
package/lib/encodings.js
CHANGED
|
@@ -21,6 +21,14 @@ Encodings.encodingMethods = {
|
|
|
21
21
|
br: zlib.createBrotliCompress
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
Encodings.encodingMethodDefaultOptions = {
|
|
25
|
+
gzip: {},
|
|
26
|
+
deflate: {},
|
|
27
|
+
br: {
|
|
28
|
+
[zlib.constants.BROTLI_PARAM_QUALITY]: 4
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
// how we treat `Accept-Encoding: *`
|
|
25
33
|
Encodings.wildcardAcceptEncoding = ['gzip', 'deflate']
|
|
26
34
|
// our preferred encodings
|
package/lib/index.js
CHANGED
|
@@ -31,8 +31,22 @@ module.exports = (options = {}) => {
|
|
|
31
31
|
|
|
32
32
|
// `options.br = false` would remove it as a preferred encoding
|
|
33
33
|
const preferredEncodings = Encodings.preferredEncodings.filter((encoding) => options[encoding] !== false && options[encoding] !== null)
|
|
34
|
+
const encodingOptions = {}
|
|
35
|
+
preferredEncodings.forEach((encoding) => {
|
|
36
|
+
encodingOptions[encoding] = {
|
|
37
|
+
...Encodings.encodingMethodDefaultOptions[encoding],
|
|
38
|
+
...(options[encoding] || {})
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
Object.assign(compressMiddleware, {
|
|
43
|
+
preferredEncodings,
|
|
44
|
+
encodingOptions
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
return compressMiddleware
|
|
34
48
|
|
|
35
|
-
|
|
49
|
+
async function compressMiddleware (ctx, next) {
|
|
36
50
|
ctx.vary('Accept-Encoding')
|
|
37
51
|
|
|
38
52
|
await next()
|
|
@@ -76,7 +90,7 @@ module.exports = (options = {}) => {
|
|
|
76
90
|
ctx.res.removeHeader('Content-Length')
|
|
77
91
|
|
|
78
92
|
const compress = Encodings.encodingMethods[encoding]
|
|
79
|
-
const stream = ctx.body = compress(
|
|
93
|
+
const stream = ctx.body = compress(encodingOptions[encoding])
|
|
80
94
|
|
|
81
95
|
if (body instanceof Stream) {
|
|
82
96
|
body.pipe(stream)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koa-compress",
|
|
3
3
|
"description": "Compress middleware for koa",
|
|
4
|
-
"version": "5.0
|
|
4
|
+
"version": "5.1.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jonathan Ong",
|
|
7
7
|
"email": "me@jongleberry.com",
|
|
@@ -13,20 +13,20 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"bytes": "^3.0.0",
|
|
15
15
|
"compressible": "^2.0.0",
|
|
16
|
-
"http-errors": "^1.
|
|
16
|
+
"http-errors": "^1.8.0",
|
|
17
17
|
"koa-is-json": "^1.0.0",
|
|
18
|
-
"statuses": "^2.0.
|
|
18
|
+
"statuses": "^2.0.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"eslint": "^
|
|
22
|
-
"eslint-config-standard": "^
|
|
23
|
-
"eslint-plugin-import": "^2.
|
|
21
|
+
"eslint": "^7.32.0",
|
|
22
|
+
"eslint-config-standard": "^16.0.3",
|
|
23
|
+
"eslint-plugin-import": "^2.24.0",
|
|
24
24
|
"eslint-plugin-node": "^11.0.0",
|
|
25
|
-
"eslint-plugin-promise": "^
|
|
26
|
-
"eslint-plugin-standard": "^
|
|
27
|
-
"jest": "^
|
|
28
|
-
"koa": "^2.
|
|
29
|
-
"supertest": "^
|
|
25
|
+
"eslint-plugin-promise": "^5.1.0",
|
|
26
|
+
"eslint-plugin-standard": "^5.0.0",
|
|
27
|
+
"jest": "^27.0.6",
|
|
28
|
+
"koa": "^2.13.1",
|
|
29
|
+
"supertest": "^6.1.6"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"eslint": "eslint --ignore-path .gitignore .",
|