Skip to content
Myr

refactored res.send()

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 0704f14 · Browse files · 2 files+11 added−11 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+11 added−11 removed

  • other:+11 added−11 removed

2 files+11 added−11 removed

modified:lib/http.js+1 added-1 removed
58 unmodified lines
5960 // expose objects to each other61 this.use(function(req, res, next){62 req.query = req.query || {};63 res.headers = { 'X-Powered-By': 'Express' };63 res.setHeader('X-Powered-By', 'Express');64 req.app = res.app = self;65 req.res = res;66 res.req = req;67 req.next = next;
377 unmodified lines
modified:lib/response.js+10 added-10 removed
38 unmodified lines
39 * @api public40 */4142res.send = function(body, headers, status){43 // Allow status as second arg43 // allow status as second arg44 if ('number' == typeof headers) {45 status = headers,46 headers = null;47 }4849 // Defaults50 status = status || 200;49 // default status50 status = status || this.statusCode;5152 // Allow 0 args as 20452 // allow 0 args as 20453 if (!arguments.length) body = status = 204;5455 // Determine content type55 // determine content type56 switch (typeof body) {57 case 'number':58 if (!this.header('Content-Type')) {59 this.contentType('.txt');
22 unmodified lines
82 }83 break;84 }8586 // Populate Content-Length86 // populate Content-Length87 if (!this.header('Content-Length')) {88 this.header('Content-Length', body instanceof Buffer89 ? body.length90 : Buffer.byteLength(body));91 }9293 // Merge headers passed93 // merge headers passed94 if (headers) {95 var fields = Object.keys(headers);96 for (var i = 0, len = fields.length; i < len; ++i) {97 var field = fields[i];98 this.header(field, headers[field]);99 }100 }101102 // Strip irrelevant headers102 // strip irrelevant headers103 if (204 === status) {104 this.removeHeader('Content-Type');105 this.removeHeader('Content-Length');106 }107108 // Respond109 this.writeHead(status, this.headers);108 // respond109 this.statusCode = status;110 this.end('HEAD' == this.req.method ? undefined : body);111};112113/**
239 unmodified lines