compression
Advanced tools
Comparing version
@@ -0,1 +1,15 @@ | ||
1.6.0 / 2015-09-29 | ||
================== | ||
* Skip compression when response has `Cache-Control: no-transform` | ||
* deps: accepts@~1.3.0 | ||
- deps: mime-types@~2.1.7 | ||
- deps: negotiator@0.6.0 | ||
* deps: compressible@~2.0.6 | ||
- deps: mime-db@'>= 1.19.0 < 2' | ||
* deps: on-headers@~1.0.1 | ||
- perf: enable strict mode | ||
* deps: vary@~1.1.0 | ||
- Only accept valid field names in the `field` argument | ||
1.5.2 / 2015-07-30 | ||
@@ -2,0 +16,0 @@ ================== |
27
index.js
@@ -33,2 +33,9 @@ /*! | ||
/** | ||
* Module variables. | ||
* @private | ||
*/ | ||
var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/ | ||
/** | ||
* Compress response data with gzip / deflate. | ||
@@ -139,2 +146,8 @@ * | ||
// determine if the entity should be transformed | ||
if (!shouldTransform(req, res)) { | ||
nocompress('no transform') | ||
return | ||
} | ||
// vary | ||
@@ -251,1 +264,15 @@ vary(res, 'Accept-Encoding') | ||
} | ||
/** | ||
* Determine if the entity should be transformed. | ||
* @private | ||
*/ | ||
function shouldTransform(req, res) { | ||
var cacheControl = res.getHeader('Cache-Control') | ||
// Don't compress for Cache-Control: no-transform | ||
// https://tools.ietf.org/html/rfc7234#section-5.2.2.4 | ||
return !cacheControl | ||
|| !cacheControlNoTransformRegExp.test(cacheControl) | ||
} |
{ | ||
"name": "compression", | ||
"description": "Node.js compression middleware", | ||
"version": "1.5.2", | ||
"version": "1.6.0", | ||
"contributors": [ | ||
@@ -12,13 +12,13 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>", | ||
"dependencies": { | ||
"accepts": "~1.2.12", | ||
"accepts": "~1.3.0", | ||
"bytes": "2.1.0", | ||
"compressible": "~2.0.5", | ||
"compressible": "~2.0.6", | ||
"debug": "~2.2.0", | ||
"on-headers": "~1.0.0", | ||
"vary": "~1.0.1" | ||
"on-headers": "~1.0.1", | ||
"vary": "~1.1.0" | ||
}, | ||
"devDependencies": { | ||
"istanbul": "0.3.17", | ||
"mocha": "2.2.5", | ||
"supertest": "1.0.1" | ||
"istanbul": "0.3.21", | ||
"mocha": "2.3.3", | ||
"supertest": "1.1.0" | ||
}, | ||
@@ -25,0 +25,0 @@ "files": [ |
@@ -30,4 +30,10 @@ # compression | ||
Returns the compression middleware using the given `options`. | ||
Returns the compression middleware using the given `options`. The middleware | ||
will attempt to compress response bodies for all request that traverse through | ||
the middleware, based on the given `options`. | ||
This middleware will never compress responses that include a `Cache-Control` | ||
header with the [`no-transform` directive](https://tools.ietf.org/html/rfc7234#section-5.2.2.4), | ||
as compressing will transform the body. | ||
#### Options | ||
@@ -34,0 +40,0 @@ |
20450
7.22%218
10.66%234
2.63%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated