Commit 2dd5453a authored by Leo Iannacone's avatar Leo Iannacone

update external libraries

parent 09129e47
1.4.1 / 2015-02-15
==================
* deps: accepts@~1.2.4
- deps: mime-types@~2.0.9
- deps: negotiator@0.5.1
1.4.0 / 2015-02-01
==================
* Prefer `gzip` over `deflate` on the server
- Not all clients agree on what "deflate" coding means
1.3.1 / 2015-01-31
==================
* deps: accepts@~1.2.3
- deps: mime-types@~2.0.8
* deps: compressible@~2.0.2
- deps: mime-db@'>= 1.1.2 < 2'
1.3.0 / 2014-12-30
==================
* Export the default `filter` function for wrapping
* deps: accepts@~1.2.2
- deps: mime-types@~2.0.7
- deps: negotiator@0.5.0
* deps: debug@~2.1.1
1.2.2 / 2014-12-10
==================
* Fix `.end` to only proxy to `.end`
- Fixes an issue with Node.js 0.11.14
* deps: accepts@~1.1.4
- deps: mime-types@~2.0.4
1.2.1 / 2014-11-23
==================
* deps: accepts@~1.1.3
- deps: mime-types@~2.0.3
1.2.0 / 2014-10-16
==================
* deps: debug@~2.1.0
- Implement `DEBUG_FD` env variable support
1.1.2 / 2014-10-15
==================
* deps: accepts@~1.1.2
- Fix error when media type has invalid parameter
- deps: negotiator@0.4.9
1.1.1 / 2014-10-12
==================
* deps: accepts@~1.1.1
- deps: mime-types@~2.0.2
- deps: negotiator@0.4.8
* deps: compressible@~2.0.1
- deps: mime-db@1.x
1.1.0 / 2014-09-07
==================
* deps: accepts@~1.1.0
* deps: compressible@~2.0.0
* deps: debug@~2.0.0
1.0.11 / 2014-08-10
===================
* deps: on-headers@~1.0.0
* deps: vary@~1.0.0
1.0.10 / 2014-08-05
===================
* deps: compressible@~1.1.1
- Fix upper-case Content-Type characters prevent compression
1.0.9 / 2014-07-20
==================
* Add `debug` messages
* deps: accepts@~1.0.7
- deps: negotiator@0.4.7
1.0.8 / 2014-06-20
==================
* deps: accepts@~1.0.5
- use `mime-types`
1.0.7 / 2014-06-11
==================
* use vary module for better `Vary` behavior
* deps: accepts@1.0.3
* deps: compressible@1.1.0
1.0.6 / 2014-06-03
==================
* fix regression when negotiation fails
1.0.5 / 2014-06-03
==================
* fix listeners for delayed stream creation
- fixes regression for certain `stream.pipe(res)` situations
1.0.4 / 2014-06-03
==================
* fix adding `Vary` when value stored as array
* fix back-pressure behavior
* fix length check for `res.end`
1.0.3 / 2014-05-29
==================
* use `accepts` for negotiation
* use `on-headers` to handle header checking
* deps: bytes@1.0.0
1.0.2 / 2014-04-29
==================
* only version compatible with node.js 0.8
* support headers given to `res.writeHead`
* deps: bytes@0.3.0
* deps: negotiator@0.4.3
1.0.1 / 2014-03-08
==================
* bump negotiator
* use compressible
* use .headersSent (drops 0.8 support)
* handle identity;q=0 case
(The MIT License)
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
Copyright (c) 2014 Douglas Christopher Wilson <doug@somethingdoug.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# compression
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
[![Gratipay][gratipay-image]][gratipay-url]
Node.js compression middleware.
The following compression codings are supported:
- deflate
- gzip
## Install
```bash
$ npm install compression
```
## API
```js
var compression = require('compression')
```
### compression([options])
Returns the compression middleware using the given `options`.
#### Options
`compression()` accepts these properties in the options object. In addition to
those listed below, [zlib](http://nodejs.org/api/zlib.html) options may be
passed in to the options object.
##### chunkSize
The default value is `zlib.Z_DEFAULT_CHUNK`, or `16384`.
See [Node.js documentation](http://nodejs.org/api/zlib.html#zlib_memory_usage_tuning)
regarding the usage.
##### filter
A function to decide if the response should be considered for compression.
This function is called as `filter(req, res)` and is expected to return
`true` to consider the response for compression, or `false` to not compress
the response.
The default filter function uses the [compressible](https://www.npmjs.com/package/compressible)
module to determine if `res.getHeader('Content-Type')` is compressible.
##### level
The level of zlib compression to apply to responses. A higher level will result
in better compression, but will take longer to complete. A lower level will
result in less compression, but will be much faster.
This is an integer in the range of `0` (no compression) to `9` (maximum
compression). The special value `-1` can be used to mean the "default
compression level", which is a default compromise between speed and
compression (currently equivalent to level 6).
- `-1` Default compression level (also `zlib.Z_DEFAULT_COMPRESSION`).
- `0` No compression (also `zlib.Z_NO_COMPRESSION`).
- `1` Fastest compression (also `zlib.Z_BEST_SPEED`).
- `2`
- `3`
- `4`
- `5`
- `6` (currently what `zlib.Z_DEFAULT_COMPRESSION` points to).
- `7`
- `8`
- `9` Best compression (also `zlib.Z_BEST_COMPRESSION`).
The default value is `zlib.Z_DEFAULT_COMPRESSION`, or `-1`.
**Note** in the list above, `zlib` is from `zlib = require('zlib')`.
##### memLevel
This specifies how much memory should be allocated for the internal compression
state and is an integer in the range of `1` (minimum level) and `9` (maximum
level).
The default value is `zlib.Z_DEFAULT_MEMLEVEL`, or `8`.
See [Node.js documentation](http://nodejs.org/api/zlib.html#zlib_memory_usage_tuning)
regarding the usage.
##### strategy
This is used to tune the compression algorithm. This value only affects the
compression ratio, not the correctness of the compressed output, even if it
is not set appropriately.
- `zlib.Z_DEFAULT_STRATEGY` Use for normal data.
- `zlib.Z_FILTERED` Use for data produced by a filter (or predictor).
Filtered data consists mostly of small values with a somewhat random
distribution. In this case, the compression algorithm is tuned to
compress them better. The effect is to force more Huffman coding and less
string matching; it is somewhat intermediate between `zlib.Z_DEFAULT_STRATEGY`
and `zlib.Z_HUFFMAN_ONLY`.
- `zlib.Z_FIXED` Use to prevent the use of dynamic Huffman codes, allowing
for a simpler decoder for special applications.
- `zlib.Z_HUFFMAN_ONLY` Use to force Huffman encoding only (no string match).
- `zlib.Z_RLE` Use to limit match distances to one (run-length encoding).
This is designed to be almost as fast as `zlib.Z_HUFFMAN_ONLY`, but give
better compression for PNG image data.
**Note** in the list above, `zlib` is from `zlib = require('zlib')`.
##### threshold
The byte threshold for the response body size before compression is considered
for the response, defaults to `1kb`. This is a number of bytes, any string
accepted by the [bytes](https://www.npmjs.com/package/bytes) module, or `false`.
##### windowBits
The default value is `zlib.Z_DEFAULT_WINDOWBITS`, or `15`.
See [Node.js documentation](http://nodejs.org/api/zlib.html#zlib_memory_usage_tuning)
regarding the usage.
#### .filter
The default `filter` function. This is used to construct a custom filter
function that is an extension of the default function.
```js
app.use(compression({filter: shouldCompress}))
function shouldCompress(req, res) {
if (req.headers['x-no-compression']) {
// don't compress responses with this request header
return false
}
// fallback to standard filter function
return compression.filter(req, res)
}
```
### res.flush
This module adds a `res.flush()` method to force the partially-compressed
response to be flushed to the client.
## Examples
### express/connect
When using this module with express or connect, simply `app.use` the module as
high as you like. Requests that pass through the middleware will be compressed.
```js
var compression = require('compression')
var express = require('express')
var app = express()
// compress all requests
app.use(compression())
// add all routes
```
### Server-Sent Events
Because of the nature of compression this module does not work out of the box
with server-sent events. To compress content, a window of the output needs to
be buffered up in order to get good compression. Typically when using server-sent
events, there are certain block of data that need to reach the client.
You can achieve this by calling `res.flush()` when you need the data written to
actually make it to the client.
```js
var compression = require('compression')
var express = require('express')
var app = express()
// compress responses
app.use(compression())
// server-sent event stream
app.get('/events', function (req, res) {
res.setHeader('Content-Type', 'text/event-stream')
res.setHeader('Cache-Control', 'no-cache')
// send a ping approx every 2 seconds
var timer = setInterval(function () {
res.write('data: ping\n\n')
// !!! this is the important part
res.flush()
}, 2000)
res.on('close', function () {
clearInterval(timer)
})
})
```
## License
[MIT](LICENSE)
[npm-image]: https://img.shields.io/npm/v/compression.svg?style=flat
[npm-url]: https://npmjs.org/package/compression
[travis-image]: https://img.shields.io/travis/expressjs/compression.svg?style=flat
[travis-url]: https://travis-ci.org/expressjs/compression
[coveralls-image]: https://img.shields.io/coveralls/expressjs/compression.svg?style=flat
[coveralls-url]: https://coveralls.io/r/expressjs/compression?branch=master
[downloads-image]: https://img.shields.io/npm/dm/compression.svg?style=flat
[downloads-url]: https://npmjs.org/package/compression
[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat
[gratipay-url]: https://www.gratipay.com/dougwilson/
/*!
* compression
* Copyright(c) 2010 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module dependencies.
* @private
*/
var accepts = require('accepts')
var bytes = require('bytes')
var compressible = require('compressible')
var debug = require('debug')('compression')
var onHeaders = require('on-headers')
var vary = require('vary')
var zlib = require('zlib')
/**
* Module exports.
*/
module.exports = compression
module.exports.filter = shouldCompress
/**
* Compress response data with gzip / deflate.
*
* @param {Object} options
* @return {Function} middleware
* @public
*/
function compression(options) {
var opts = options || {}
var filter = opts.filter || shouldCompress
var threshold = typeof opts.threshold === 'string'
? bytes(opts.threshold)
: opts.threshold
if (threshold == null) {
threshold = 1024
}
return function compression(req, res, next){
var compress = true
var listeners = []
var write = res.write
var on = res.on
var end = res.end
var stream
// see #8
req.on('close', function(){
res.write = res.end = noop
});
// flush is noop by default
res.flush = noop;
// proxy
res.write = function(chunk, encoding){
if (!this._header) {
// if content-length is set and is lower
// than the threshold, don't compress
var len = Number(res.getHeader('Content-Length'))
checkthreshold(len)
this._implicitHeader();
}
return stream
? stream.write(new Buffer(chunk, encoding))
: write.call(res, chunk, encoding);
};
res.end = function(chunk, encoding){
var len
if (chunk) {
len = Buffer.isBuffer(chunk)
? chunk.length
: Buffer.byteLength(chunk, encoding)
}
if (!this._header) {
len = Number(this.getHeader('Content-Length')) || len
checkthreshold(len)
this._implicitHeader()
}
return stream
? stream.end(chunk, encoding)
: end.call(res, chunk, encoding)
};
res.on = function(type, listener){
if (!listeners || type !== 'drain') {
return on.call(this, type, listener)
}
if (stream) {
return stream.on(type, listener)
}
// buffer listeners for future stream
listeners.push([type, listener])
return this
}
function checkthreshold(len) {
if (compress && len < threshold) {
debug('size below threshold')
compress = false
}
}
function nocompress(msg) {
debug('no compression' + (msg ? ': ' + msg : ''))
addListeners(res, on, listeners)
listeners = null
}
onHeaders(res, function(){
// determine if request is filtered
if (!filter(req, res)) {
nocompress('filtered')
return
}
// vary
vary(res, 'Accept-Encoding')
if (!compress) {
nocompress()
return
}
var encoding = res.getHeader('Content-Encoding') || 'identity';
// already encoded
if ('identity' !== encoding) {
nocompress('already encoded')
return
}
// head
if ('HEAD' === req.method) {
nocompress('HEAD request')
return
}
// compression method
var accept = accepts(req)
var method = accept.encoding(['gzip', 'deflate', 'identity'])
// we really don't prefer deflate
if (method === 'deflate' && accept.encoding(['gzip'])) {
method = accept.encoding(['gzip', 'identity'])
}
// negotiation failed
if (!method || method === 'identity') {
nocompress('not acceptable')
return
}
// compression stream
debug('%s compression', method)
stream = method === 'gzip'
? zlib.createGzip(opts)
: zlib.createDeflate(opts)
// add bufferred listeners to stream
addListeners(stream, stream.on, listeners)
// overwrite the flush method
res.flush = function(){
stream.flush();
}
// header fields
res.setHeader('Content-Encoding', method);
res.removeHeader('Content-Length');
// compression
stream.on('data', function(chunk){
if (write.call(res, chunk) === false) {
stream.pause()
}
});
stream.on('end', function(){
end.call(res);
});
on.call(res, 'drain', function() {
stream.resume()
});
});
next();
};
}
/**
* Add bufferred listeners to stream
* @private
*/
function addListeners(stream, on, listeners) {
for (var i = 0; i < listeners.length; i++) {
on.apply(stream, listeners[i])
}
}
/**
* No-operation function
* @private
*/
function noop(){}
/**
* Default filter function.
* @private
*/
function shouldCompress(req, res) {
var type = res.getHeader('Content-Type')
if (type === undefined || !compressible(type)) {
debug('%s not compressible', type)
return false
}
return true
}
1.2.4 / 2015-02-14
==================
* Support Node.js 0.6
* deps: mime-types@~2.0.9
- deps: mime-db@~1.7.0
* deps: negotiator@0.5.1
- Fix preference sorting to be stable for long acceptable lists
1.2.3 / 2015-01-31
==================
* deps: mime-types@~2.0.8
- deps: mime-db@~1.6.0
1.2.2 / 2014-12-30
==================
* deps: mime-types@~2.0.7
- deps: mime-db@~1.5.0
1.2.1 / 2014-12-30
==================