Skip to content

Commit db89408

Browse files
committed
add functionality
1 parent c87d82f commit db89408

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ module.exports.filter = shouldCompress
3737

3838
var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/
3939

40+
var encodingSupported = ['gzip', 'deflate', 'identity']
41+
4042
/**
4143
* Compress response data with gzip / deflate.
4244
*
@@ -51,6 +53,7 @@ function compression (options) {
5153
// options
5254
var filter = opts.filter || shouldCompress
5355
var threshold = bytes.parse(opts.threshold)
56+
var defaultEncoding = opts.defaultEncoding || 'identity'
5457

5558
if (threshold == null) {
5659
threshold = 1024
@@ -182,12 +185,21 @@ function compression (options) {
182185
method = accept.encoding(['gzip', 'identity'])
183186
}
184187

188+
// if no method is found, use the default encoding
189+
if (encodingSupported.indexOf(defaultEncoding) !== -1 && req.headers['accept-encoding'].split(',')[0] === '') {
190+
method = defaultEncoding
191+
}
192+
185193
// negotiation failed
186194
if (!method || method === 'identity') {
187195
nocompress('not acceptable')
188196
return
189197
}
190198

199+
if (opts.defaultEncoding) {
200+
opts.defaultEncoding = undefined
201+
}
202+
191203
// compression stream
192204
debug('%s compression', method)
193205
stream = method === 'gzip'

0 commit comments

Comments
 (0)