Removed `res.header(field, value)`
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 c44f018 · Browse files · 4 files·+5 added−82 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+5 added−82 removed
- tests:+2 added−64 removed
- other:+3 added−18 removed
Provenance
- Commit
76fd462- Tree
5eec8e9- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
c44f018
4 files changed+5 added−82 removed
modified:lib/router/index.js+1 added-1 removed
295 unmodified lines296 297 Router.prototype._options = function(req, res){298 var path = parse(req.url).pathname299 , body = this._optionsFor(path).join(',');300- res.header('Allow', body).send(body);300+ res.set('Allow', body).send(body);301 };302 303 /**304 * Return an array of HTTP verbs or "options" for `path`.112 unmodified linesmodified:lib/response.js+2 added-17 removed
339 unmodified lines340 return this.getHeader(field);341 };342 343 /**344- * Set or get response header `field` with optional `val`.345- *346- * @param {String} name347- * @param {String} val348- * @return {ServerResponse} for chaining349- * @api public350- */351-352-res.header = function(field, val){353- if (1 == arguments.length) return this.getHeader(field);354- this.setHeader(field, val);355- return this;356-};357-358-/**344 * Clear cookie `name`.345 *346 * @param {String} name347 * @param {Object} options103 unmodified lines451 url = arguments[1];452 }453 454 // setup redirect map470- var map = { back: req.header('Referrer', '/') };455+ var map = { back: req.get('Referrer') || '/' };456 457 // perform redirect458 url = map[url] || url;459 9 unmodified lines469 url = path + '/' + url;470 }471 472 // Absolute488- var host = req.header('Host');473+ var host = req.get('Host');474 url = req.protocol + '://' + host + url;475 }476 477 // Support text/{plain,html} by default84 unmodified linesdeleted:test/res.header.js-62 removed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
var express = require('../') , request = require('./support/http');
describe('res', function(){ describe('.header(field)', function(){ it('should get the response header field', function(done){ var app = express();
app.use(function(req, res){ res.setHeader('Content-Type', 'text/x-foo'); res.end(res.header('Content-Type')); });
request(app) .get('/') .end(function(res){ res.body.should.equal('text/x-foo'); done(); }) }) }) describe('.header(field, value)', function(){ it('should set the response header field', function(done){ var app = express();
app.use(function(req, res){ res.header('Content-Type', 'text/x-foo'); res.end(); });
request(app) .get('/') .end(function(res){ res.headers.should.have.property('content-type', 'text/x-foo'); done(); }) }) it('should chain when arity > 1', function(done){ var app = express();
app.use(function(req, res){ res .header('Content-Type', 'text/x-foo') .header('X-Foo', 'bar') .header('X-Baz', undefined) .end(); });
request(app) .get('/') .end(function(res){ res.headers.should.have.property('content-type', 'text/x-foo'); res.headers.should.have.property('x-foo', 'bar'); res.headers.should.have.property('x-baz', 'undefined'); done(); }) }) })})modified:test/res.send.js+2 added-2 removed
93 unmodified lines94 it('should not override Content-Type', function(done){95 var app = express();96 97 app.use(function(req, res){98- res.header('Content-Type', 'text/plain').send('hey');98+ res.set('Content-Type', 'text/plain').send('hey');99 });100 101 request(app)102 .get('/')27 unmodified lines130 it('should not override Content-Type', function(done){131 var app = express();132 133 app.use(function(req, res){134- res.header('Content-Type', 'text/plain').send(new Buffer('hey'));134+ res.set('Content-Type', 'text/plain').send(new Buffer('hey'));135 });136 137 request(app)138 .get('/')82 unmodified lines