Skip to content

Commit 162f14b

Browse files
committed
test: add test for enforceEnconding
1 parent 24203e0 commit 162f14b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

index.js

+4-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.
@@ -202,11 +202,14 @@ function compression (options) {
202202
method = enforceEncoding === '*' ? 'gzip' : enforceEncoding
203203
}
204204

205+
console.log(method)
206+
205207
// negotiation failed
206208
if (!method || method === 'identity') {
207209
nocompress('not acceptable')
208210
return
209211
}
212+
210213
// compression stream
211214
debug('%s compression', method)
212215
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)