Skip to content

Commit 4e8e083

Browse files
committed
test: add test for enforceEnconding
1 parent 24203e0 commit 4e8e083

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/
4545
var SUPPORTED_ENCODING = hasBrotliSupport ? ['br', 'gzip', 'deflate', 'identity'] : ['gzip', 'deflate', 'identity']
4646
var PREFERRED_ENCODING = hasBrotliSupport ? ['br', 'gzip'] : ['gzip']
4747

48-
var encodingSupported = ['*', 'gzip', 'deflate', 'identity']
48+
var encodingSupported = ['*', 'gzip', 'deflate', 'identity', 'br']
4949

5050
/**
5151
* Compress response data with gzip / deflate.
@@ -207,6 +207,7 @@ function compression (options) {
207207
nocompress('not acceptable')
208208
return
209209
}
210+
210211
// compression stream
211212
debug('%s compression', method)
212213
stream = method === 'gzip'

test/compression.js

+13
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,19 @@ describe('compression()', function () {
934934
.expect(200, 'hello, world', done)
935935
})
936936

937+
brotli('should compress when enforceEncoding is brotli', function (done) {
938+
var server = createServer({ threshold: 0, enforceEncoding: 'br' }, function (req, res) {
939+
res.setHeader('Content-Type', 'text/plain')
940+
res.end('hello, world')
941+
})
942+
943+
request(server)
944+
.get('/')
945+
.set('Accept-Encoding', '')
946+
.expect('Content-Encoding', 'br')
947+
.expect(200, done)
948+
})
949+
937950
it('should not compress when enforceEncoding is unknown', function (done) {
938951
var server = createServer({ threshold: 0, enforceEncoding: 'bogus' }, function (req, res) {
939952
res.setHeader('Content-Type', 'text/plain')

0 commit comments

Comments
 (0)