Skip to content
Myr

Removed header field support

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 986916c · Browse files · 2 files+3 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+3 added−24 removed

  • tests:+0 added−4 removed
  • other:+3 added−20 removed

2 files+3 added−24 removed

modified:lib/response.js+3 added-20 removed
20 unmodified lines
21 , basename = path.basename22 , join = path.join;2324/**25 * Send a response with the given `body` and optional `headers` and `status` code.25 * Send a response with the given `body` and optional `status` code.26 *27 * Examples:28 *29 * res.send(new Buffer('wahoo'));30 * res.send({ some: 'json' });31 * res.send('<p>some html</p>');32 * res.send('Sorry, cant find that', 404);33 * res.send('text', { 'Content-Type': 'text/plain' }, 201);33 * res.send(404);34 *35 * @param {String|Object|Number|Buffer} body or status37 * @param {Object|Number} headers or status36 * @param {Number} status37 * @return {ServerResponse}38 * @api public39 */4043res.send = function(body, headers, status){44 // allow status as second arg45 if ('number' == typeof headers) {46 status = headers,47 headers = null;48 }4941res.send = function(body, status){42 // default status43 status = status || this.statusCode;4445 // determine content type
28 unmodified lines
74 ? body.length75 : Buffer.byteLength(body));76 }7786 // merge headers passed87 if (headers) {88 var fields = Object.keys(headers);89 for (var i = 0, len = fields.length; i < len; ++i) {90 var field = fields[i];91 this.header(field, headers[field]);92 }93 }9478 // strip irrelevant headers79 if (204 == status || 304 == status) {80 this.removeHeader('Content-Type');81 this.removeHeader('Content-Length');
5 unmodified lines
87 return this;88};8990/**108 * Send JSON response with `obj`, optional `headers`, and optional `status`.91 * Send JSON response with `obj` and optional `status`.92 *93 * Examples:94 *95 * res.json(null);
309 unmodified lines
modified:test/response.test.js-4 removed
23 unmodified lines
24 app.get('/error', function(req, res, next){25 res.json('oh noes!', 500);26 });2728 app.get('/headers', function(req, res, next){29 res.json(undefined, { 'X-Foo': 'bar' }, 302);30 });3128 assert.response(app,29 { url: '/error' },30 { body: '"oh noes!"'31 , status: 500
735 unmodified lines