add deprecation message to non-plural req.accepts*
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 83bbf09 · Browse files · 7 files·+159 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+159 added−17 removed
- tests:+142 added−4 removed
- other:+17 added−13 removed
Provenance
- Commit
2cccbc1- Tree
eb4a43d- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
83bbf09
7 files changed+159 added−17 removed
modified:lib/request.js+16 added-13 removed
1 unmodified line2 * Module dependencies.3 */4 5 var accepts = require('accepts');6+var deprecate = require('depd')('express');7 var typeis = require('type-is');8 var http = require('http');9 var fresh = require('fresh');10 var parseRange = require('range-parser');95 unmodified lines106 return accept.types.apply(accept, arguments);107 };108 109 /**109- * Check if the given `encoding` is accepted.110+ * Check if the given `encoding`s are accepted.111 *111- * @param {String} encoding112+ * @param {String} ...encoding113 * @return {Boolean}114 * @api public115 */116 116-req.acceptsEncoding = // backwards compatibility117 req.acceptsEncodings = function(){118 var accept = accepts(this);119 return accept.encodings.apply(accept, arguments);120 };121 122+req.acceptsEncoding = deprecate.function(req.acceptsEncodings,123+ 'req.acceptsEncoding: Use acceptsEncodings instead');124+125 /**123- * To do: update docs.124- *125- * Check if the given `charset` is acceptable,126+ * Check if the given `charset`s are acceptable,127 * otherwise you should respond with 406 "Not Acceptable".128 *128- * @param {String} charset129+ * @param {String} ...charset130 * @return {Boolean}131 * @api public132 */133 133-req.acceptsCharset = // backwards compatibility134 req.acceptsCharsets = function(){135 var accept = accepts(this);136 return accept.charsets.apply(accept, arguments);137 };138 139+req.acceptsCharset = deprecate.function(req.acceptsCharsets,140+ 'req.acceptsCharset: Use acceptsCharsets instead');141+142 /**140- * To do: update docs.141- *142- * Check if the given `lang` is acceptable,143+ * Check if the given `lang`s are acceptable,144 * otherwise you should respond with 406 "Not Acceptable".145 *145- * @param {String} lang146+ * @param {String} ...lang147 * @return {Boolean}148 * @api public149 */150 150-req.acceptsLanguage = // backwards compatibility151 req.acceptsLanguages = function(){152 var accept = accepts(this);153 return accept.languages.apply(accept, arguments);154 };155 156+req.acceptsLanguage = deprecate.function(req.acceptsLanguages,157+ 'req.acceptsLanguage: Use acceptsLanguages instead');158+159 /**160 * Parse Range header field,161 * capping to the given `size`.162 *283 unmodified linesmodified:test/req.acceptsCharset.js+3 added-3 removed
7 unmodified lines8910111212131415165 unmodified lines222324252626272829304 unmodified lines353637383939404142436 unmodified lines7 unmodified lines it('should return true', function(done){ var app = express();
app.use(function(req, res, next){ res.end(req.acceptsCharsets('utf-8') ? 'yes' : 'no'); res.end(req.acceptsCharset('utf-8') ? 'yes' : 'no'); });
request(app) .get('/')5 unmodified lines it('should return true when present', function(done){ var app = express();
app.use(function(req, res, next){ res.end(req.acceptsCharsets('utf-8') ? 'yes' : 'no'); res.end(req.acceptsCharset('utf-8') ? 'yes' : 'no'); });
request(app) .get('/')4 unmodified lines it('should return false otherwise', function(done){ var app = express();
app.use(function(req, res, next){ res.end(req.acceptsCharsets('utf-8') ? 'yes' : 'no'); res.end(req.acceptsCharset('utf-8') ? 'yes' : 'no'); });
request(app) .get('/')6 unmodified linesadded:test/req.acceptsCharsets.js+49 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
var express = require('../') , request = require('supertest');
describe('req', function(){ describe('.acceptsCharsets(type)', function(){ describe('when Accept-Charset is not present', function(){ it('should return true', function(done){ var app = express();
app.use(function(req, res, next){ res.end(req.acceptsCharsets('utf-8') ? 'yes' : 'no'); });
request(app) .get('/') .expect('yes', done); }) })
describe('when Accept-Charset is not present', function(){ it('should return true when present', function(done){ var app = express();
app.use(function(req, res, next){ res.end(req.acceptsCharsets('utf-8') ? 'yes' : 'no'); });
request(app) .get('/') .set('Accept-Charset', 'foo, bar, utf-8') .expect('yes', done); })
it('should return false otherwise', function(done){ var app = express();
app.use(function(req, res, next){ res.end(req.acceptsCharsets('utf-8') ? 'yes' : 'no'); });
request(app) .get('/') .set('Accept-Charset', 'foo, bar') .expect('no', done); }) }) })})modified:test/req.acceptsEncoding.js+1 added-1 removed
12345667891026 unmodified lines
var express = require('../') , request = require('supertest');
describe('req', function(){ describe('.acceptsEncodings', function(){ describe('.acceptsEncoding', function(){ it('should be true if encoding accpeted', function(done){ var app = express();
app.use(function(req, res){26 unmodified linesadded:test/req.acceptsEncodings.js+36 added
123456789101112131415161718192021222324252627282930313233343536
var express = require('../') , request = require('supertest');
describe('req', function(){ describe('.acceptsEncodingss', function(){ it('should be true if encoding accpeted', function(done){ var app = express();
app.use(function(req, res){ req.acceptsEncodings('gzip').should.be.ok; req.acceptsEncodings('deflate').should.be.ok; res.end(); });
request(app) .get('/') .set('Accept-Encoding', ' gzip, deflate') .expect(200, done); })
it('should be false if encoding not accpeted', function(done){ var app = express();
app.use(function(req, res){ req.acceptsEncodings('bogus').should.not.be.ok; res.end(); });
request(app) .get('/') .set('Accept-Encoding', ' gzip, deflate') .expect(200, done); }) })})added:test/req.acceptsLanguages.js+53 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
var express = require('../') , request = require('supertest');
describe('req', function(){ describe('.acceptsLanguages', function(){ it('should be true if language accpeted', function(done){ var app = express();
app.use(function(req, res){ req.acceptsLanguages('en-us').should.be.ok; req.acceptsLanguages('en').should.be.ok; res.end(); });
request(app) .get('/') .set('Accept-Language', 'en;q=.5, en-us') .expect(200, done); })
it('should be false if language not accpeted', function(done){ var app = express();
app.use(function(req, res){ req.acceptsLanguages('es').should.not.be.ok; res.end(); });
request(app) .get('/') .set('Accept-Language', 'en;q=.5, en-us') .expect(200, done); })
describe('when Accept-Language is not present', function(){ it('should always return true', function(done){ var app = express();
app.use(function(req, res){ req.acceptsLanguages('en').should.be.ok; req.acceptsLanguages('es').should.be.ok; req.acceptsLanguages('jp').should.be.ok; res.end(); });
request(app) .get('/') .expect(200, done); }) }) })})modified:History.md+1 added
1 unreleased2 ==========3 4+ * add deprecation message to non-plural `req.accepts*`5 * deprecate things with `depd` module6 * fix behavior when handling request without routes7 * fix handling when `route.all` is only route8 * restore `req.params` after invoking router1683 unmodified lines