Removed `req.header(field)`
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 76fd462 · Browse files · 3 files·+45 added−57 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+45 added−57 removed
- tests:+39 added−48 removed
- other:+6 added−9 removed
Provenance
- Commit
85d6964- Tree
ca98a13- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
76fd462
3 files changed+45 added−57 removed
modified:lib/request.js+6 added-9 removed
30 unmodified lines31 * interchangeable.32 *33 * Examples:34 *35- * req.header('Content-Type');35 * req.get('Content-Type');36 * // => "text/plain"37 * 39- * req.header('content-type');38 * req.get('content-type');39 * // => "text/plain"40 * 43- * req.header('Something');41+ * req.get('Something');42 * // => undefined43 * 44 * @param {String} name45 * @return {String} 46 * @api public47 */48 51-req.header = 49 req.get = function(name){50 switch (name = name.toLowerCase()) {51 case 'referer':52 case 'referrer':30 unmodified lines83 * @api public84 */85 86 req.accepts = function(type){90- return utils.accepts(type, this.header('Accept'));87+ return utils.accepts(type, this.get('Accept'));88 };89 90 /**91 * Check if the given `charset` is acceptable,46 unmodified lines138 * @api public139 */140 141 req.__defineGetter__('accepted', function(){145- var accept = this.header('Accept');142+ var accept = this.get('Accept');143 return accept144 ? utils.parseAccept(accept)145 : [];146 });11 unmodified lines158 * @api public159 */160 161 req.__defineGetter__('acceptedLanguages', function(){165- var accept = this.header('Accept-Language');162+ var accept = this.get('Accept-Language');163 return accept164 ? utils165 .parseQuality(accept)166 .map(function(obj){15 unmodified lines182 * @api public183 */184 185 req.__defineGetter__('acceptedCharsets', function(){189- var accept = this.header('Accept-Charset');186+ var accept = this.get('Accept-Charset');187 return accept188 ? utils189 .parseQuality(accept)190 .map(function(obj){73 unmodified lines264 * @api public265 */266 267 req.is = function(type){271- var ct = this.headers['content-type'];268+ var ct = this.get('Content-Type');269 if (!ct) return false;270 ct = ct.split(';')[0];271 if (!~type.indexOf('/')) type = mime.lookup(type);272 if (~type.indexOf('*')) {89 unmodified linesadded:test/req.get.js+39 added
123456789101112131415161718192021222324252627282930313233343536373839
var express = require('../') , request = require('./support/http');
describe('req', function(){ describe('.get(field)', function(){ it('should return the header field value', function(done){ var app = express();
app.use(function(req, res){ res.end(req.get('Content-Type')); });
request(app) .post('/') .set('Content-Type', 'application/json') .end(function(res){ res.body.should.equal('application/json'); done(); }); })
it('should special-case Referer', function(done){ var app = express();
app.use(function(req, res){ res.end(req.get('Referer')); });
request(app) .post('/') .set('Referrer', 'http://foobar.com') .end(function(res){ res.body.should.equal('http://foobar.com'); done(); }); }) })})No newline at end of filedeleted:test/req.header.js-48 removed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
var express = require('../') , request = require('./support/http');
describe('req', function(){ describe('.header(field)', function(){ it('should return the header field value', function(done){ var app = express();
app.use(function(req, res){ res.end(req.header('Content-Type')); });
request(app) .post('/') .set('Content-Type', 'application/json') .end(function(res){ res.body.should.equal('application/json'); done(); }); })
it('should special-case Referer', function(done){ var app = express();
app.use(function(req, res){ res.end(req.header('Referer')); });
request(app) .post('/') .set('Referrer', 'http://foobar.com') .end(function(res){ res.body.should.equal('http://foobar.com'); done(); }); }) })})
describe('req', function(){ describe('.get(field)', function(){ it('should alias req.header(field)', function(){ express.request.get .should.equal(express.request.header); }) })})