Replace res.send() with res.send = require("response-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 2173d00 · Browse files · 2 files·+2 added−77 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+2 added−77 removed
- other:+2 added−77 removed
Provenance
- Commit
96e4014- Tree
1bef77d- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
2173d00
2 files changed+2 added−77 removed
modified:lib/response.js+1 added-76 removed
11 unmodified lines12 , normalizeTypes = require('./utils').normalizeTypes13 , statusCodes = http.STATUS_CODES14 , send = connect.static.send15 , cookie = require('cookie')16- , crc = require('crc')16 , mime = connect.mime17 , basename = path.basename18 , extname = path.extname19 , join = path.join;56 unmodified lines76 * @return {ServerResponse}77 * @api public78 */79 81-res.send = function(body){82- var req = this.req83- , head = 'HEAD' == req.method84- , len;80+res.send = require('response-send');81 86- // allow status / body87- if (2 == arguments.length) {88- // res.send(body, status) backwards compat89- if ('number' != typeof body && 'number' == typeof arguments[1]) {90- this.statusCode = arguments[1];91- } else {92- this.statusCode = body;93- body = arguments[1];94- }95- }96-97-98- // convert string objects to primitives99- if (body instanceof String) body = body.toString();100-101- switch (typeof body) {102- // response status103- case 'number':104- this.get('Content-Type') || this.type('txt');105- this.statusCode = body;106- body = http.STATUS_CODES[body];107- break;108- // string defaulting to html109- case 'string':110- if (!this.get('Content-Type')) {111- this.charset = this.charset || 'utf-8';112- this.type('html');113- }114- break;115- case 'boolean':116- case 'object':117- if (null == body) {118- body = '';119- } else if (Buffer.isBuffer(body)) {120- this.get('Content-Type') || this.type('bin');121- } else {122- return this.json(body);123- }124- break;125- }126-127- // populate Content-Length128- if (undefined !== body && !this.get('Content-Length')) {129- this.set('Content-Length', len = Buffer.isBuffer(body)130- ? body.length131- : Buffer.byteLength(body));132- }133-134- // ETag support135- // TODO: W/ support136- if (len > 1024) {137- if (!this.get('ETag')) this.set('ETag', Buffer.isBuffer(body)138- ? crc.buffer.crc32(body)139- : crc.crc32(body));140- }141-142- // freshness143- if (req.fresh) this.statusCode = 304;144-145- // strip irrelevant headers146- if (204 == this.statusCode || 304 == this.statusCode) {147- this.removeHeader('Content-Type');148- this.removeHeader('Content-Length');149- body = '';150- }151-152- // respond153- this.end(head ? null : body);154- return this;155-};156-82 /**83 * Send JSON response.84 *85 * Examples:529 unmodified linesmodified:package.json+1 added-1 removed
11 unmodified lines12131415161718181920212223 unmodified lines11 unmodified lines "dependencies": { "connect": "2.3.6", "commander": "0.6.1", "range-parser": "0.0.4", "response-send": "0.0.1", "mkdirp": "0.3.3", "cookie": "0.0.3", "crc": "0.2.0", "fresh": "0.1.0", "methods": "0.0.1", "debug": "*" },23 unmodified lines