Skip to content

Commit 073f59f

Browse files
committed
change defaultEncoding to enforceEnconding
1 parent 86d65a9 commit 073f59f

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ The default value is `zlib.Z_DEFAULT_WINDOWBITS`, or `15`.
139139
See [Node.js documentation](http://nodejs.org/api/zlib.html#zlib_memory_usage_tuning)
140140
regarding the usage.
141141

142-
##### defaultEncoding
142+
##### enforceEncoding
143143

144144
This is the default encoding to use when the client does not specify an encoding in the request's [Accept-Encoding](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding) header.
145145

index.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function compression (options) {
5353
// options
5454
var filter = opts.filter || shouldCompress
5555
var threshold = bytes.parse(opts.threshold)
56-
var defaultEncoding = opts.defaultEncoding || 'identity'
56+
var enforceEncoding = opts.enforceEncoding || 'identity'
5757

5858
if (threshold == null) {
5959
threshold = 1024
@@ -181,8 +181,8 @@ function compression (options) {
181181
var method = negotiator.encoding(['gzip', 'deflate', 'identity'], ['gzip'])
182182

183183
// if no method is found, use the default encoding
184-
if (encodingSupported.indexOf(defaultEncoding) !== -1 && !req.headers['accept-encoding']) {
185-
method = defaultEncoding === '*' ? 'gzip' : defaultEncoding
184+
if (encodingSupported.indexOf(enforceEncoding) !== -1 && !req.headers['accept-encoding']) {
185+
method = enforceEncoding === '*' ? 'gzip' : enforceEncoding
186186
}
187187

188188
// negotiation failed
@@ -191,10 +191,6 @@ function compression (options) {
191191
return
192192
}
193193

194-
if (opts.defaultEncoding) {
195-
opts.defaultEncoding = undefined
196-
}
197-
198194
// compression stream
199195
debug('%s compression', method)
200196
stream = method === 'gzip'

test/compression.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,9 @@ describe('compression()', function () {
658658
})
659659
})
660660

661-
describe('defaultEncoding', function () {
661+
describe('enforceEncoding', function () {
662662
it('should compress the provided encoding and not the default encoding', function (done) {
663-
var server = createServer({ threshold: 0, defaultEncoding: 'deflate' }, function (req, res) {
663+
var server = createServer({ threshold: 0, enforceEncoding: 'deflate' }, function (req, res) {
664664
res.setHeader('Content-Type', 'text/plain')
665665
res.end('hello, world')
666666
})
@@ -672,8 +672,8 @@ describe('compression()', function () {
672672
.expect(200, 'hello, world', done)
673673
})
674674

675-
it('should not compress when defaultEncoding is identity', function (done) {
676-
var server = createServer({ threshold: 0, defaultEncoding: 'identity' }, function (req, res) {
675+
it('should not compress when enforceEncoding is identity', function (done) {
676+
var server = createServer({ threshold: 0, enforceEncoding: 'identity' }, function (req, res) {
677677
res.setHeader('Content-Type', 'text/plain')
678678
res.end('hello, world')
679679
})
@@ -685,8 +685,8 @@ describe('compression()', function () {
685685
.expect(200, 'hello, world', done)
686686
})
687687

688-
it('should compress when defaultEncoding is gzip', function (done) {
689-
var server = createServer({ threshold: 0, defaultEncoding: 'gzip' }, function (req, res) {
688+
it('should compress when enforceEncoding is gzip', function (done) {
689+
var server = createServer({ threshold: 0, enforceEncoding: 'gzip' }, function (req, res) {
690690
res.setHeader('Content-Type', 'text/plain')
691691
res.end('hello, world')
692692
})
@@ -698,8 +698,8 @@ describe('compression()', function () {
698698
.expect(200, 'hello, world', done)
699699
})
700700

701-
it('should compress when defaultEncoding is deflate', function (done) {
702-
var server = createServer({ threshold: 0, defaultEncoding: 'deflate' }, function (req, res) {
701+
it('should compress when enforceEncoding is deflate', function (done) {
702+
var server = createServer({ threshold: 0, enforceEncoding: 'deflate' }, function (req, res) {
703703
res.setHeader('Content-Type', 'text/plain')
704704
res.end('hello, world')
705705
})
@@ -711,8 +711,8 @@ describe('compression()', function () {
711711
.expect(200, 'hello, world', done)
712712
})
713713

714-
it('should not compress when defaultEncoding is unknown', function (done) {
715-
var server = createServer({ threshold: 0, defaultEncoding: 'bogus' }, function (req, res) {
714+
it('should not compress when enforceEncoding is unknown', function (done) {
715+
var server = createServer({ threshold: 0, enforceEncoding: 'bogus' }, function (req, res) {
716716
res.setHeader('Content-Type', 'text/plain')
717717
res.end('hello, world')
718718
})
@@ -724,8 +724,8 @@ describe('compression()', function () {
724724
.expect(200, 'hello, world', done)
725725
})
726726

727-
it('should be gzip if no accept-encoding is sent when defaultEncoding is *', function (done) {
728-
var server = createServer({ threshold: 0, defaultEncoding: '*' }, function (req, res) {
727+
it('should be gzip if no accept-encoding is sent when enforceEncoding is *', function (done) {
728+
var server = createServer({ threshold: 0, enforceEncoding: '*' }, function (req, res) {
729729
res.setHeader('Content-Type', 'text/plain')
730730
res.end('hello, world')
731731
})

0 commit comments

Comments
 (0)