Skip to content

Commit ae9da60

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

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

index.js

Lines changed: 6 additions & 1 deletion
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,16 @@ 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+
213+
console.log(optsBrotli)
214+
console.log(opts)
210215
// compression stream
211216
debug('%s compression', method)
212217
stream = method === 'gzip'

test/compression.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ describe('compression()', function () {
485485
request(server)
486486
.get('/')
487487
.set('Accept-Encoding', 'gzip')
488-
.expect('Content-Encoding', 'gzip', done)
488+
.expect('Content-Encoding', 'gzip')
489+
.expect(200, 'hello, world', done)
489490
})
490491

491492
it('should return false writing after end', function (done) {
@@ -513,7 +514,8 @@ describe('compression()', function () {
513514
request(server)
514515
.get('/')
515516
.set('Accept-Encoding', 'deflate')
516-
.expect('Content-Encoding', 'deflate', done)
517+
.expect('Content-Encoding', 'deflate')
518+
.expect(200, 'hello, world', done)
517519
})
518520
})
519521

@@ -527,7 +529,8 @@ describe('compression()', function () {
527529
request(server)
528530
.get('/')
529531
.set('Accept-Encoding', 'br')
530-
.expect('Content-Encoding', 'br', done)
532+
.expect('Content-Encoding', 'br')
533+
.expect(200, 'hello, world', done)
531534
})
532535
})
533536

@@ -934,6 +937,19 @@ describe('compression()', function () {
934937
.expect(200, 'hello, world', done)
935938
})
936939

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

0 commit comments

Comments
 (0)