File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ module.exports.filter = shouldCompress
37
37
38
38
var cacheControlNoTransformRegExp = / (?: ^ | , ) \s * ?n o - t r a n s f o r m \s * ?(?: , | $ ) /
39
39
40
+ var encodingSupported = [ 'gzip' , 'deflate' , 'identity' ]
41
+
40
42
/**
41
43
* Compress response data with gzip / deflate.
42
44
*
@@ -51,6 +53,7 @@ function compression (options) {
51
53
// options
52
54
var filter = opts . filter || shouldCompress
53
55
var threshold = bytes . parse ( opts . threshold )
56
+ var defaultEncoding = opts . defaultEncoding || 'identity'
54
57
55
58
if ( threshold == null ) {
56
59
threshold = 1024
@@ -182,12 +185,21 @@ function compression (options) {
182
185
method = accept . encoding ( [ 'gzip' , 'identity' ] )
183
186
}
184
187
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
+
185
193
// negotiation failed
186
194
if ( ! method || method === 'identity' ) {
187
195
nocompress ( 'not acceptable' )
188
196
return
189
197
}
190
198
199
+ if ( opts . defaultEncoding ) {
200
+ opts . defaultEncoding = undefined
201
+ }
202
+
191
203
// compression stream
192
204
debug ( '%s compression' , method )
193
205
stream = method === 'gzip'
You can’t perform that action at this time.
0 commit comments