Skip to content

Commit

Permalink
test: add test for enforceEnconding
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohansebas committed Dec 6, 2024
1 parent 24203e0 commit 4e8e083
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/
var SUPPORTED_ENCODING = hasBrotliSupport ? ['br', 'gzip', 'deflate', 'identity'] : ['gzip', 'deflate', 'identity']
var PREFERRED_ENCODING = hasBrotliSupport ? ['br', 'gzip'] : ['gzip']

var encodingSupported = ['*', 'gzip', 'deflate', 'identity']
var encodingSupported = ['*', 'gzip', 'deflate', 'identity', 'br']

/**
* Compress response data with gzip / deflate.
Expand Down Expand Up @@ -207,6 +207,7 @@ function compression (options) {
nocompress('not acceptable')
return
}

// compression stream
debug('%s compression', method)
stream = method === 'gzip'
Expand Down
13 changes: 13 additions & 0 deletions test/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,19 @@ describe('compression()', function () {
.expect(200, 'hello, world', done)
})

brotli('should compress when enforceEncoding is brotli', function (done) {
var server = createServer({ threshold: 0, enforceEncoding: 'br' }, function (req, res) {
res.setHeader('Content-Type', 'text/plain')
res.end('hello, world')
})

request(server)
.get('/')
.set('Accept-Encoding', '')
.expect('Content-Encoding', 'br')
.expect(200, done)
})

it('should not compress when enforceEncoding is unknown', function (done) {
var server = createServer({ threshold: 0, enforceEncoding: 'bogus' }, function (req, res) {
res.setHeader('Content-Type', 'text/plain')
Expand Down

0 comments on commit 4e8e083

Please sign in to comment.