diff --git a/lib/request.js b/lib/request.js index 1eb7f9ca16a..702f3c8e968 100644 --- a/lib/request.js +++ b/lib/request.js @@ -147,9 +147,9 @@ req.acceptsEncodings = function(){ * Returns the best matching charset or an array of acceptable charsets. * * The `charset` argument(s) can be: - * - A single charset string (e.g., "utf-8") - * - Multiple charset strings as arguments (e.g., `"utf-8", "iso-8859-1"`) - * - A comma-delimited list of charsets (e.g., `"utf-8, iso-8859-1"`) + * - A single charset string (e.g., 'utf-8') + * - Multiple charset strings as arguments (e.g., `'utf-8', 'iso-8859-1'`) + * - An array of charsets (e.g., `['utf-8', 'iso-8859-1']`) * * Examples: * @@ -160,7 +160,7 @@ req.acceptsEncodings = function(){ * req.acceptsCharsets('utf-8', 'iso-8859-1'); * // => "utf-8" * - * req.acceptsCharsets('utf-8, utf-16'); + * req.acceptsCharsets(['utf-8', 'utf-16']); * // => "utf-8" * * @param {...String} charsets - The charset(s) to check against the `Accept-Charset` header. diff --git a/test/req.acceptsCharsets.js b/test/req.acceptsCharsets.js index 2df68ae1097..677a37ab6b1 100644 --- a/test/req.acceptsCharsets.js +++ b/test/req.acceptsCharsets.js @@ -59,5 +59,18 @@ describe('req', function(){ .expect('iso-8859-1', done); }) }) + + it('should accept an array of charsets', function (done) { + var app = express(); + + app.use(function(req, res, next){ + res.end(req.acceptsCharsets(['utf-8', 'iso-8859-1'])); + }); + + request(app) + .get('/') + .set('Accept-Charset', 'iso-8859-1, utf-8') + .expect('iso-8859-1', done); + }) }) }) diff --git a/test/req.acceptsEncodings.js b/test/req.acceptsEncodings.js index 9f8973cdfb8..5f89c135c61 100644 --- a/test/req.acceptsEncodings.js +++ b/test/req.acceptsEncodings.js @@ -35,5 +35,31 @@ describe('req', function(){ .set('Accept-Encoding', ' gzip, deflate') .expect(200, { bogus: false }, done) }) + + it('should accept an array of encodings', function (done) { + var app = express(); + + app.get('/', function (req, res) { + res.send(req.acceptsEncodings(['deflate', 'gzip'])) + }) + + request(app) + .get('/') + .set('Accept-Encoding', 'gzip;q=0.5, deflate') + .expect(200, 'deflate', done) + }) + + it('should accept an argument list of encodings', function (done) { + var app = express(); + + app.get('/', function (req, res) { + res.send(req.acceptsEncodings('gzip', 'deflate')) + }) + + request(app) + .get('/') + .set('Accept-Encoding', 'gzip, deflate') + .expect(200, 'gzip', done) + }) }) }) diff --git a/test/req.acceptsLanguages.js b/test/req.acceptsLanguages.js index e5629fbc323..72625572a5e 100644 --- a/test/req.acceptsLanguages.js +++ b/test/req.acceptsLanguages.js @@ -36,6 +36,32 @@ describe('req', function(){ .expect(200, { es: false }, done) }) + it('should accept an array of languages', function (done) { + var app = express(); + + app.get('/', function (req, res) { + res.send(req.acceptsLanguages(['en-us', 'en'])) + }) + + request(app) + .get('/') + .set('Accept-Language', 'en;q=.5, en-us') + .expect(200, 'en-us', done) + }) + + it('should accept an argument list of languages', function (done) { + var app = express(); + + app.get('/', function (req, res) { + res.send(req.acceptsLanguages('jp', 'en')) + }) + + request(app) + .get('/') + .set('Accept-Language', 'en;q=.5, en-us') + .expect(200, 'en', done) + }) + describe('when Accept-Language is not present', function(){ it('should always return language', function (done) { var app = express();