Skip to content

Commit 0af2a9a

Browse files
authored
fix: don't handle * in enforceEncoding (#213)
1 parent 82c9cb5 commit 0af2a9a

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

.github/workflows/ci.yml

+1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ 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']
47+
var encodingSupported = ['gzip', 'deflate', 'identity', 'br']
4848

4949
/**
5050
* Compress response data with gzip / deflate.
@@ -200,7 +200,7 @@ function compression (options) {
200200

201201
// if no method is found, use the default encoding
202202
if (!req.headers['accept-encoding'] && encodingSupported.indexOf(enforceEncoding) !== -1) {
203-
method = enforceEncoding === '*' ? 'gzip' : enforceEncoding
203+
method = enforceEncoding
204204
}
205205

206206
// negotiation failed

test/compression.js

+3-3
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)