koa-compress 3.0.0 → 3.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/HISTORY.md +4 -0
- package/README.md +4 -5
- package/index.js +10 -0
- package/package.json +11 -11
package/HISTORY.md
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# Koa Compress
|
|
2
2
|
|
|
3
|
-
[](https://github.com/koajs/compress/actions?query=workflow%3A%22Node.js+CI%22+branch%3Amaster)
|
|
4
4
|
[](https://codecov.io/gh/koajs/compress)
|
|
5
|
-
[](https://greenkeeper.io/)
|
|
6
5
|
|
|
7
6
|
Compress middleware for Koa
|
|
8
7
|
|
|
@@ -29,7 +28,7 @@ The options are passed to `zlib`: http://nodejs.org/api/zlib.html#zlib_options
|
|
|
29
28
|
### filter
|
|
30
29
|
|
|
31
30
|
An optional function that checks the response content type to decide whether to compress.
|
|
32
|
-
By default, it uses [compressible](https://github.com/
|
|
31
|
+
By default, it uses [compressible](https://github.com/jshttp/compressible).
|
|
33
32
|
|
|
34
33
|
### threshold
|
|
35
34
|
|
|
@@ -38,8 +37,8 @@ Default `1024` bytes or `1kb`.
|
|
|
38
37
|
|
|
39
38
|
## Manually turning compression on and off
|
|
40
39
|
|
|
41
|
-
You can always enable compression by setting `
|
|
42
|
-
You can always disable compression by setting `
|
|
40
|
+
You can always enable compression by setting `ctx.compress = true`.
|
|
41
|
+
You can always disable compression by setting `ctx.compress = false`.
|
|
43
42
|
This bypasses the filter check.
|
|
44
43
|
|
|
45
44
|
```js
|
package/index.js
CHANGED
|
@@ -20,6 +20,11 @@ const encodingMethods = {
|
|
|
20
20
|
deflate: zlib.createDeflate
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Regex to match no-transform directive in a cache-control header
|
|
25
|
+
*/
|
|
26
|
+
const NO_TRANSFORM_REGEX = /(?:^|,)\s*?no-transform\s*?(?:,|$)/
|
|
27
|
+
|
|
23
28
|
/**
|
|
24
29
|
* Compress middleware.
|
|
25
30
|
*
|
|
@@ -48,6 +53,11 @@ module.exports = (options = {}) => {
|
|
|
48
53
|
// forced compression or implied
|
|
49
54
|
if (!(ctx.compress === true || filter(ctx.response.type))) return
|
|
50
55
|
|
|
56
|
+
// Don't compress for Cache-Control: no-transform
|
|
57
|
+
// https://tools.ietf.org/html/rfc7234#section-5.2.1.6
|
|
58
|
+
const cacheControl = ctx.response.get('Cache-Control')
|
|
59
|
+
if (cacheControl && NO_TRANSFORM_REGEX.test(cacheControl)) return
|
|
60
|
+
|
|
51
61
|
// identity
|
|
52
62
|
const encoding = ctx.acceptsEncodings('gzip', 'deflate', 'identity')
|
|
53
63
|
if (!encoding) ctx.throw(406, 'supported encodings: gzip, deflate, identity')
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koa-compress",
|
|
3
3
|
"description": "Compress middleware for koa",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jonathan Ong",
|
|
7
7
|
"email": "me@jongleberry.com",
|
|
@@ -17,18 +17,15 @@
|
|
|
17
17
|
"statuses": "^1.0.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"eslint": "^
|
|
21
|
-
"eslint-config-standard": "^
|
|
22
|
-
"eslint-config-standard-react": "^6.0.0",
|
|
23
|
-
"eslint-plugin-flowtype": "^2.46.1",
|
|
20
|
+
"eslint": "^6.0.0",
|
|
21
|
+
"eslint-config-standard": "^14.1.1",
|
|
24
22
|
"eslint-plugin-import": "^2.9.0",
|
|
25
|
-
"eslint-plugin-node": "^
|
|
26
|
-
"eslint-plugin-promise": "^
|
|
27
|
-
"eslint-plugin-
|
|
28
|
-
"
|
|
29
|
-
"jest": "^22.4.3",
|
|
23
|
+
"eslint-plugin-node": "^11.0.0",
|
|
24
|
+
"eslint-plugin-promise": "^4.0.0",
|
|
25
|
+
"eslint-plugin-standard": "^4.0.1",
|
|
26
|
+
"jest": "^25.3.0",
|
|
30
27
|
"koa": "^2.0.1",
|
|
31
|
-
"supertest": "^
|
|
28
|
+
"supertest": "^4.0.2"
|
|
32
29
|
},
|
|
33
30
|
"scripts": {
|
|
34
31
|
"eslint": "eslint --ignore-path .gitignore .",
|
|
@@ -41,5 +38,8 @@
|
|
|
41
38
|
],
|
|
42
39
|
"jest": {
|
|
43
40
|
"testEnvironment": "node"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">= 8.0.0"
|
|
44
44
|
}
|
|
45
45
|
}
|