Socket
Socket
Sign inDemoInstall

compression

Package Overview
Dependencies
10
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.6.1 to 1.6.2

13

HISTORY.md

@@ -0,1 +1,14 @@

1.6.2 / 2016-05-12
==================
* deps: accepts@~1.3.3
- deps: mime-types@~2.1.11
- deps: negotiator@0.6.1
* deps: bytes@2.3.0
- Drop partial bytes on all parsed units
- Fix parsing byte string that looks like hex
- perf: hoist regular expressions
* deps: compressible@~2.0.8
- deps: mime-db@'>= 1.23.0 < 2'
1.6.1 / 2016-01-19

@@ -2,0 +15,0 @@ ==================

81

index.js

@@ -42,3 +42,3 @@ /*!

*
* @param {Object} options
* @param {Object} [options]
* @return {Function} middleware

@@ -48,3 +48,3 @@ * @public

function compression(options) {
function compression (options) {
var opts = options || {}

@@ -60,13 +60,14 @@

return function compression(req, res, next){
return function compression (req, res, next) {
var ended = false
var length
var listeners = []
var write = res.write
var on = res.on
var end = res.end
var stream
var _end = res.end
var _on = res.on
var _write = res.write
// flush
res.flush = function flush() {
res.flush = function flush () {
if (stream) {

@@ -79,3 +80,3 @@ stream.flush()

res.write = function(chunk, encoding){
res.write = function write (chunk, encoding) {
if (ended) {

@@ -91,6 +92,6 @@ return false

? stream.write(new Buffer(chunk, encoding))
: write.call(this, chunk, encoding)
};
: _write.call(this, chunk, encoding)
}
res.end = function(chunk, encoding){
res.end = function end (chunk, encoding) {
if (ended) {

@@ -110,3 +111,3 @@ return false

if (!stream) {
return end.call(this, chunk, encoding)
return _end.call(this, chunk, encoding)
}

@@ -121,7 +122,7 @@

: stream.end()
};
}
res.on = function(type, listener){
res.on = function on (type, listener) {
if (!listeners || type !== 'drain') {
return on.call(this, type, listener)
return _on.call(this, type, listener)
}

@@ -139,9 +140,9 @@

function nocompress(msg) {
function nocompress (msg) {
debug('no compression: %s', msg)
addListeners(res, on, listeners)
addListeners(res, _on, listeners)
listeners = null
}
onHeaders(res, function(){
onHeaders(res, function onResponseHeaders () {
// determine if request is filtered

@@ -168,6 +169,6 @@ if (!filter(req, res)) {

var encoding = res.getHeader('Content-Encoding') || 'identity';
var encoding = res.getHeader('Content-Encoding') || 'identity'
// already encoded
if ('identity' !== encoding) {
if (encoding !== 'identity') {
nocompress('already encoded')

@@ -178,3 +179,3 @@ return

// head
if ('HEAD' === req.method) {
if (req.method === 'HEAD') {
nocompress('HEAD request')

@@ -209,23 +210,23 @@ return

// header fields
res.setHeader('Content-Encoding', method);
res.removeHeader('Content-Length');
res.setHeader('Content-Encoding', method)
res.removeHeader('Content-Length')
// compression
stream.on('data', function(chunk){
if (write.call(res, chunk) === false) {
stream.on('data', function onStreamData (chunk) {
if (_write.call(res, chunk) === false) {
stream.pause()
}
});
})
stream.on('end', function(){
end.call(res);
});
stream.on('end', function onStreamEnd () {
_end.call(res)
})
on.call(res, 'drain', function() {
_on.call(res, 'drain', function onResponseDrain () {
stream.resume()
});
});
})
})
next();
};
next()
}
}

@@ -238,3 +239,3 @@

function addListeners(stream, on, listeners) {
function addListeners (stream, on, listeners) {
for (var i = 0; i < listeners.length; i++) {

@@ -249,3 +250,3 @@ on.apply(stream, listeners[i])

function chunkLength(chunk, encoding) {
function chunkLength (chunk, encoding) {
if (!chunk) {

@@ -265,3 +266,3 @@ return 0

function shouldCompress(req, res) {
function shouldCompress (req, res) {
var type = res.getHeader('Content-Type')

@@ -282,3 +283,3 @@

function shouldTransform(req, res) {
function shouldTransform (req, res) {
var cacheControl = res.getHeader('Cache-Control')

@@ -288,4 +289,4 @@

// https://tools.ietf.org/html/rfc7234#section-5.2.2.4
return !cacheControl
|| !cacheControlNoTransformRegExp.test(cacheControl)
return !cacheControl ||
!cacheControlNoTransformRegExp.test(cacheControl)
}
{
"name": "compression",
"description": "Node.js compression middleware",
"version": "1.6.1",
"version": "1.6.2",
"contributors": [

@@ -12,5 +12,5 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>",

"dependencies": {
"accepts": "~1.3.1",
"bytes": "2.2.0",
"compressible": "~2.0.7",
"accepts": "~1.3.3",
"bytes": "2.3.0",
"compressible": "~2.0.8",
"debug": "~2.2.0",

@@ -21,4 +21,8 @@ "on-headers": "~1.0.1",

"devDependencies": {
"istanbul": "0.4.2",
"mocha": "2.3.4",
"eslint": "2.9.0",
"eslint-config-standard": "5.3.1",
"eslint-plugin-promise": "1.1.0",
"eslint-plugin-standard": "1.3.2",
"istanbul": "0.4.3",
"mocha": "2.4.5",
"supertest": "1.1.0"

@@ -35,2 +39,3 @@ },

"scripts": {
"lint": "eslint **/*.js",
"test": "mocha --check-leaks --reporter spec --bail",

@@ -37,0 +42,0 @@ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --check-leaks --reporter dot",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc