Skip to content

Commit be8381f

Browse files
committed
fix: don't handle * in enforceEncoding
1 parent 82c9cb5 commit be8381f

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
test:
4040
runs-on: ubuntu-latest
4141
strategy:
42+
fail-fast: false
4243
matrix:
4344
name:
4445
- Node.js 0.8

index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/
4444
var SUPPORTED_ENCODING = hasBrotliSupport ? ['br', 'gzip', 'deflate', 'identity'] : ['gzip', 'deflate', 'identity']
4545
var PREFERRED_ENCODING = hasBrotliSupport ? ['br', 'gzip'] : ['gzip']
4646

47-
var encodingSupported = ['*', 'gzip', 'deflate', 'identity', 'br']
48-
4947
/**
5048
* Compress response data with gzip / deflate.
5149
*
@@ -199,8 +197,8 @@ function compression (options) {
199197
var method = negotiator.encoding(SUPPORTED_ENCODING, PREFERRED_ENCODING)
200198

201199
// if no method is found, use the default encoding
202-
if (!req.headers['accept-encoding'] && encodingSupported.indexOf(enforceEncoding) !== -1) {
203-
method = enforceEncoding === '*' ? 'gzip' : enforceEncoding
200+
if (!req.headers['accept-encoding']) {
201+
method = ['gzip', 'deflate', 'identity', 'br'].includes(enforceEncoding) ? enforceEncoding : method
204202
}
205203

206204
// negotiation failed

test/compression.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ describe('compression()', function () {
960960
.expect(200, 'hello, world', done)
961961
})
962962

963-
it('should be gzip if no accept-encoding is sent when enforceEncoding is *', function (done) {
963+
it('should not compress when enforceEnconding is *', function (done) {
964964
var server = createServer({ threshold: 0, enforceEncoding: '*' }, function (req, res) {
965965
res.setHeader('Content-Type', 'text/plain')
966966
res.end('hello, world')
@@ -969,8 +969,8 @@ describe('compression()', function () {
969969
request(server)
970970
.get('/')
971971
.set('Accept-Encoding', '')
972-
.expect('Content-Encoding', 'gzip')
973-
.expect(200, 'hello, world', done)
972+
.expect(shouldNotHaveHeader('Content-Encoding'))
973+
.expect(200, done)
974974
})
975975
})
976976
})

0 commit comments

Comments
 (0)