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 CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ 3.1.0 / 2020-04-15
3
+
4
+ * support no-transform @Pawda
5
+
2
6
  3.0.0 / 2018-04-14
3
7
  ==================
4
8
 
package/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Koa Compress
2
2
 
3
- [![Build Status](https://travis-ci.org/koajs/compress.svg?branch=master)](https://travis-ci.org/koajs/compress)
3
+ [![Node.js CI](https://github.com/koajs/compress/workflows/Node.js%20CI/badge.svg?branch=master)](https://github.com/koajs/compress/actions?query=workflow%3A%22Node.js+CI%22+branch%3Amaster)
4
4
  [![codecov](https://codecov.io/gh/koajs/compress/branch/master/graph/badge.svg)](https://codecov.io/gh/koajs/compress)
5
- [![Greenkeeper badge](https://badges.greenkeeper.io/koajs/compress.svg)](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/expressjs/compressible).
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 `this.compress = true`.
42
- You can always disable compression by setting `this.compress = false`.
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.0.0",
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": "^4.19.0",
21
- "eslint-config-standard": "^11.0.0",
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": "^6.0.1",
26
- "eslint-plugin-promise": "^3.7.0",
27
- "eslint-plugin-react": "^7.7.0",
28
- "eslint-plugin-standard": "^3.0.1",
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": "^3.0.0"
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
  }