diff --git a/docs/api/request.md b/docs/api/request.md index eebcfaf..aca01c7 100644 --- a/docs/api/request.md +++ b/docs/api/request.md @@ -224,7 +224,7 @@ switch (this.accepts('json', 'html', 'text')) { ### req.acceptsEncodings(encodings) Check if `encodings` are acceptable, returning - the best match when true, otherwise `undefined`. + the best match when true, otherwise `identity`. ```js // Accept-Encoding: gzip diff --git a/lib/request.js b/lib/request.js index 3389dd8..afb7672 100644 --- a/lib/request.js +++ b/lib/request.js @@ -428,7 +428,7 @@ module.exports = { if (!Array.isArray(encodings)) encodings = [].slice.call(arguments); var n = new Negotiator(this.req); if (!encodings.length) return n.preferredEncodings(); - return n.preferredEncodings(encodings)[0]; + return n.preferredEncodings(encodings)[0] || 'identity'; }, /** diff --git a/test/request/acceptsEncodings.js b/test/request/acceptsEncodings.js index bec416d..0cdc189 100644 --- a/test/request/acceptsEncodings.js +++ b/test/request/acceptsEncodings.js @@ -8,6 +8,7 @@ describe('ctx.acceptsEncodings()', function(){ var ctx = context(); ctx.req.headers['accept-encoding'] = 'gzip, compress;q=0.2'; ctx.acceptsEncodings().should.eql(['gzip', 'compress', 'identity']); + ctx.acceptsEncodings('gzip', 'compress').should.equal('gzip'); }) }) @@ -15,6 +16,7 @@ describe('ctx.acceptsEncodings()', function(){ it('should return identity', function(){ var ctx = context(); ctx.acceptsEncodings().should.eql(['identity']); + ctx.acceptsEncodings('gzip', 'deflate').should.equal('identity'); }) }) })