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
3737
3838var cacheControlNoTransformRegExp = / (?: ^ | , ) \s * ?n o - t r a n s f o r m \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'
You can’t perform that action at this time.
0 commit comments