response.js
This file
Path
lib/response.js
679 lines · 15.6 KiB · JavaScript
Last changed by
add etag utilTJ Holowaychukbefore adoptionf2f0976
History of this fileTake it
The walk stopped after 200 commits: lines older than 858e4dc point at it.
wsTJ Holowaychukbefore adoption858e4dc
lines 1–11why, one step back1/**2 * Module dependencies.3 */45var fs = require('fs')6 , http = require('http')7 , path = require('path')8 , connect = require('connect')9 , utils = connect.utils10 , normalizeType = require('./utils').normalizeType11 , normalizeTypes = require('./utils').normalizeTypesadd etag utilTJ Holowaychukbefore adoptionf2f0976
line 12why, one step back12 , etag = require('./utils').etagwsTJ Holowaychukbefore adoption858e4dc
lines 13–14why, one step back13 , statusCodes = http.STATUS_CODES14 , send = connect.static.sendfixing cookies for connect 2.3.1TJ Holowaychukbefore adoption02d4384
line 15why, one step back15 , cookie = require('cookie')change res.sendfile() to use send() moduleTJ Holowaychukbefore adoptionab61837
line 16why, one step back16 , send = require('send')mergeTJ Holowaychukbefore adoption214f913
line 17why, one step back17 , crc = require('crc')Fixed: expose connects mime module. Cloases #1165TJ Holowaychukbefore adoption8956731
line 18why, one step back18 , mime = connect.mimewsTJ Holowaychukbefore adoption858e4dc
lines 19–44why, one step back19 , basename = path.basename20 , extname = path.extname21 , join = path.join;2223/**24 * Response prototype.25 */2627var res = module.exports = {28 __proto__: http.ServerResponse.prototype29};3031/**32 * Set status `code`.33 *34 * @param {Number} code35 * @return {ServerResponse}36 * @api public37 */3839res.status = function(code){40 this.statusCode = code;41 return this;42};4344/**Added `res.links(obj)`TJ Holowaychukbefore adoptione6129d8
lines 45–65why, one step back45 * Set Link header field with the given `links`.46 *47 * Examples:48 *49 * res.links({50 * next: 'http://api.example.com/users?page=2',51 * last: 'http://api.example.com/users?page=5'52 * });53 *54 * @param {Object} links55 * @return {ServerResponse}56 * @api public57 */5859res.links = function(links){60 return this.set('Link', Object.keys(links).map(function(rel){61 return '<' + links[rel] + '>; rel="' + rel + '"';62 }).join(', '));63};6465/**wsTJ Holowaychukbefore adoption858e4dc
lines 66–81why, one step back66 * Send a response.67 *68 * Examples:69 *70 * res.send(new Buffer('wahoo'));71 * res.send({ some: 'json' });72 * res.send('<p>some html</p>');73 * res.send(404, 'Sorry, cant find that');74 * res.send(404);75 *76 * @param {Mixed} body or status77 * @param {Mixed} body78 * @return {ServerResponse}79 * @api public80 */81mergeTJ Holowaychukbefore adoption214f913
lines 82–136why, one step back82res.send = function(body){83 var req = this.req84 , head = 'HEAD' == req.method85 , len;8687 // allow status / body88 if (2 == arguments.length) {89 // res.send(body, status) backwards compat90 if ('number' != typeof body && 'number' == typeof arguments[1]) {91 this.statusCode = arguments[1];92 } else {93 this.statusCode = body;94 body = arguments[1];95 }96 }9798 // convert string objects to primitives99 if (body instanceof String) body = body.toString();100101 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 }126127 // 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 }133134 // ETag support135 // TODO: W/ support136 if (len > 1024) {add etag utilTJ Holowaychukbefore adoptionf2f0976
lines 137–139why, one step back137 if (!this.get('ETag')) {138 this.set('ETag', etag(body));139 }mergeTJ Holowaychukbefore adoption214f913
lines 140–155why, one step back140 }141142 // freshness143 if (req.fresh) this.statusCode = 304;144145 // strip irrelevant headers146 if (204 == this.statusCode || 304 == this.statusCode) {147 this.removeHeader('Content-Type');148 this.removeHeader('Content-Length');149 body = '';150 }151152 // respond153 this.end(head ? null : body);154 return this;155};wsTJ Holowaychukbefore adoption858e4dc
lines 156–175why, one step back156157/**158 * Send JSON response.159 *160 * Examples:161 *162 * res.json(null);163 * res.json({ user: 'tj' });164 * res.json(500, 'oh noes!');165 * res.json(404, 'I dont have that');166 *167 * @param {Mixed} obj or status168 * @param {Mixed} obj169 * @return {ServerResponse}170 * @api public171 */172173res.json = function(obj){174 // allow status / body175 if (2 == arguments.length) {Added `res.json(obj, status)` support back for BCTJ Holowaychukbefore adoption70d6841
lines 176–182why, one step back176 // res.json(body, status) backwards compat177 if ('number' == typeof arguments[1]) {178 this.statusCode = arguments[1];179 } else {180 this.statusCode = obj;181 obj = arguments[1];182 }wsTJ Holowaychukbefore adoption858e4dc
lines 183–184why, one step back183 }184docsTJ Holowaychukbefore adoption2e8d44b
line 185why, one step back185 // settingswsTJ Holowaychukbefore adoption858e4dc
lines 186–190why, one step back186 var app = this.app187 , jsonp = app.get('jsonp callback')188 , replacer = app.get('json replacer')189 , spaces = app.get('json spaces')190 , body = JSON.stringify(obj, replacer, spaces)add "jsonp callback name" settingriadhbefore adoption5426eb0
line 191why, one step back191 , callback = this.req.query[app.get('jsonp callback name')];wsTJ Holowaychukbefore adoption858e4dc
line 192why, one step back192docsTJ Holowaychukbefore adoption2e8d44b
line 193why, one step back193 // content-typewsTJ Holowaychukbefore adoption858e4dc
lines 194–195why, one step back194 this.charset = this.charset || 'utf-8';195 this.set('Content-Type', 'application/json');add "jsonp callback name" settingriadhbefore adoption5426eb0
line 196why, one step back196 docsTJ Holowaychukbefore adoption2e8d44b
line 197why, one step back197 // jsonpwsTJ Holowaychukbefore adoption858e4dc
lines 198–199why, one step back198 if (callback && jsonp) {199 this.set('Content-Type', 'text/javascript');fix jsonp callback char restrictionsTJ Holowaychukbefore adoption89c5aff
line 200why, one step back200 body = callback.replace(/[^\[\]\w$.]/g, '') + '(' + body + ');';wsTJ Holowaychukbefore adoption858e4dc
lines 201–249why, one step back201 }202203 return this.send(body);204};205206/**207 * Transfer the file at the given `path`.208 * 209 * Automatically sets the _Content-Type_ response header field.210 * The callback `fn(err)` is invoked when the transfer is complete211 * or when an error occurs. Be sure to check `res.sentHeader`212 * if you wish to attempt responding, as the header and some data213 * may have already been transferred.214 *215 * Options:216 *217 * - `maxAge` defaulting to 0218 * - `root` root directory for relative filenames219 *220 * Examples:221 *222 * The following example illustrates how `res.sendfile()` may223 * be used as an alternative for the `static()` middleware for224 * dynamic situations. The code backing `res.sendfile()` is actually225 * the same code, so HTTP cache support etc is identical.226 *227 * app.get('/user/:uid/photos/:file', function(req, res){228 * var uid = req.params.uid229 * , file = req.params.file;230 * 231 * req.user.mayViewFilesFrom(uid, function(yes){232 * if (yes) {233 * res.sendfile('/uploads/' + uid + '/' + file);234 * } else {235 * res.send(403, 'Sorry! you cant see that.');236 * }237 * });238 * });239 *240 * @param {String} path241 * @param {Object|Function} options or fn242 * @param {Function} fn243 * @api public244 */245246res.sendfile = function(path, options, fn){247 var self = this248 , req = self.req249 , next = this.req.nextchange res.sendfile() to use send() moduleTJ Holowaychukbefore adoptionab61837
lines 250–251why, one step back250 , options = options || {}251 , done;wsTJ Holowaychukbefore adoption858e4dc
lines 252–258why, one step back252253 // support function as second arg254 if ('function' == typeof options) {255 fn = options;256 options = {};257 }258change res.sendfile() to use send() moduleTJ Holowaychukbefore adoptionab61837
lines 259–260why, one step back259 // socket errors260 req.socket.on('error', error);wsTJ Holowaychukbefore adoption858e4dc
line 261why, one step back261change res.sendfile() to use send() moduleTJ Holowaychukbefore adoptionab61837
lines 262–265why, one step back262 // errors263 function error(err) {264 if (done) return;265 done = true;wsTJ Holowaychukbefore adoption858e4dc
line 266why, one step back266change res.sendfile() to use send() moduleTJ Holowaychukbefore adoptionab61837
line 267why, one step back267 // clean upMerge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption3865168
line 268why, one step back268 cleanup();change res.sendfile() to use send() moduleTJ Holowaychukbefore adoptionab61837
line 269why, one step back269 if (!self.headerSent) self.removeHeader('Content-Disposition');wsTJ Holowaychukbefore adoption858e4dc
line 270why, one step back270change res.sendfile() to use send() moduleTJ Holowaychukbefore adoptionab61837
lines 271–272why, one step back271 // callback available272 if (fn) return fn(err);wsTJ Holowaychukbefore adoption858e4dc
line 273why, one step back273change res.sendfile() to use send() moduleTJ Holowaychukbefore adoptionab61837
lines 274–275why, one step back274 // list in limbo if there's no callback275 if (self.headerSent) return;wsTJ Holowaychukbefore adoption858e4dc
line 276why, one step back276change res.sendfile() to use send() moduleTJ Holowaychukbefore adoptionab61837
lines 277–279why, one step back277 // delegate278 next(err);279 }wsTJ Holowaychukbefore adoption858e4dc
line 280why, one step back280change res.sendfile() to use send() moduleTJ Holowaychukbefore adoptionab61837
lines 281–283why, one step back281 // streaming282 function stream() {283 if (done) return;Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption3865168
line 284why, one step back284 cleanup();change res.sendfile() to use send() moduleTJ Holowaychukbefore adoptionab61837
lines 285–287why, one step back285 if (fn) self.on('finish', fn);286 }287Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption3865168
lines 288–292why, one step back288 // cleanup289 function cleanup() {290 req.socket.removeListener('error', error);291 }292wsTJ Holowaychukbefore adoption858e4dc
line 293why, one step back293 // transferchange res.sendfile() to use send() moduleTJ Holowaychukbefore adoptionab61837
lines 294–300why, one step back294 var file = send(req, path);295 if (options.root) file.root(options.root);296 file.maxage(options.maxAge || 0);297 file.on('error', error);298 file.on('directory', next);299 file.on('stream', stream);300 file.pipe(this);Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption3865168
line 301why, one step back301 this.on('finish', cleanup);wsTJ Holowaychukbefore adoption858e4dc
lines 302–311why, one step back302};303304/**305 * Transfer the file at the given `path` as an attachment.306 *307 * Optionally providing an alternate attachment `filename`,308 * and optional callback `fn(err)`. The callback is invoked309 * when the data transfer is complete, or when an error has310 * ocurred. Be sure to check `res.headerSent` if you plan to respond.311 *Added res.download() testsTJ Holowaychukbefore adoption5840b42
line 312why, one step back312 * This method uses `res.sendfile()`.wsTJ Holowaychukbefore adoption858e4dc
lines 313–326why, one step back313 *314 * @param {String} path315 * @param {String|Function} filename or fn316 * @param {Function} fn317 * @api public318 */319320res.download = function(path, filename, fn){321 // support function as second arg322 if ('function' == typeof filename) {323 fn = filename;324 filename = null;325 }326Added res.download() testsTJ Holowaychukbefore adoption5840b42
lines 327–329why, one step back327 filename = filename || path;328 this.set('Content-Disposition', 'attachment; filename="' + basename(filename) + '"');329 return this.sendfile(path, fn);wsTJ Holowaychukbefore adoption858e4dc
lines 330–401why, one step back330};331332/**333 * Set _Content-Type_ response header with `type` through `mime.lookup()`334 * when it does not contain "/", or set the Content-Type to `type` otherwise.335 *336 * Examples:337 *338 * res.type('.html');339 * res.type('html');340 * res.type('json');341 * res.type('application/json');342 * res.type('png');343 *344 * @param {String} type345 * @return {ServerResponse} for chaining346 * @api public347 */348349res.contentType =350res.type = function(type){351 return this.set('Content-Type', ~type.indexOf('/')352 ? type353 : mime.lookup(type));354};355356/**357 * Respond to the Acceptable formats using an `obj`358 * of mime-type callbacks.359 *360 * This method uses `req.accepted`, an array of361 * acceptable types ordered by their quality values.362 * When "Accept" is not present the _first_ callback363 * is invoked, otherwise the first match is used. When364 * no match is performed the server responds with365 * 406 "Not Acceptable".366 *367 * Content-Type is set for you, however if you choose368 * you may alter this within the callback using `res.type()`369 * or `res.set('Content-Type', ...)`.370 *371 * res.format({372 * 'text/plain': function(){373 * res.send('hey');374 * },375 * 376 * 'text/html': function(){377 * res.send('<p>hey</p>');378 * },379 * 380 * 'appliation/json': function(){381 * res.send({ message: 'hey' });382 * }383 * });384 *385 * In addition to canonicalized MIME types you may386 * also use extnames mapped to these types:387 *388 * res.format({389 * text: function(){390 * res.send('hey');391 * },392 * 393 * html: function(){394 * res.send('<p>hey</p>');395 * },396 * 397 * json: function(){398 * res.send({ message: 'hey' });399 * }400 * });401 *mention res.format() callbackTJ Holowaychukbefore adoptionfd42b5c
lines 402–403why, one step back402 * By default Express passes an `Error`403 * with a `.status` of 406 to `next(err)`docsTJ Holowaychukbefore adoptiond2baf11
lines 404–406why, one step back404 * if a match is not made. If you provide405 * a `.default` callback it will be invoked406 * instead.mention res.format() callbackTJ Holowaychukbefore adoptionfd42b5c
line 407why, one step back407 *wsTJ Holowaychukbefore adoption858e4dc
lines 408–412why, one step back408 * @param {Object} obj409 * @return {ServerResponse} for chaining410 * @api public411 */412Added `.default()` support to `res.format()`TJ Holowaychukbefore adoption82b5b12
line 413why, one step back413res.format = function(obj){wsTJ Holowaychukbefore adoption858e4dc
lines 414–415why, one step back414 var keys = Object.keys(obj)415 , req = this.reqAdded `.default()` support to `res.format()`TJ Holowaychukbefore adoption82b5b12
line 416why, one step back416 , next = req.next;wsTJ Holowaychukbefore adoption858e4dc
line 417why, one step back417Added `.default()` support to `res.format()`TJ Holowaychukbefore adoption82b5b12
lines 418–422why, one step back418 var fn = obj.default;419 if (fn) delete obj.default;420421 var key = req.accepts(keys);422wsTJ Holowaychukbefore adoption858e4dc
lines 423–427why, one step back423 this.set('Vary', 'Accept');424425 if (key) {426 this.set('Content-Type', normalizeType(key));427 obj[key](req, this, next);Fixed res.redirect() 406. Closes #1154TJ Holowaychukbefore adoption1311f2a
lines 428–429why, one step back428 } else if (fn) {429 fn();wsTJ Holowaychukbefore adoption858e4dc
lines 430–457why, one step back430 } else {431 var err = new Error('Not Acceptable');432 err.status = 406;433 err.types = normalizeTypes(keys);434 next(err);435 }436437 return this;438};439440/**441 * Set _Content-Disposition_ header to _attachment_ with optional `filename`.442 *443 * @param {String} filename444 * @return {ServerResponse}445 * @api public446 */447448res.attachment = function(filename){449 if (filename) this.type(extname(filename));450 this.set('Content-Disposition', filename451 ? 'attachment; filename="' + basename(filename) + '"'452 : 'attachment');453 return this;454};455456/**457 * Set header `field` to `val`, or passMerge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption0acee67
line 458why, one step back458 * an object of header fields.wsTJ Holowaychukbefore adoption858e4dc
lines 459–475why, one step back459 *460 * Examples:461 *462 * res.set('Accept', 'application/json');463 * res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });464 *465 * Aliased as `res.header()`. 466 *467 * @param {String|Object} field468 * @param {String} val469 * @return {ServerResponse} for chaining470 * @api public471 */472473res.set = 474res.header = function(field, val){475 if (2 == arguments.length) {Added: coerce `res.set()` values to stringsTJ Holowaychukbefore adoption67ddb42
line 476why, one step back476 this.setHeader(field, '' + val);wsTJ Holowaychukbefore adoption858e4dc
lines 477–478why, one step back477 } else {478 for (var key in field) {Added: coerce `res.set()` values to stringsTJ Holowaychukbefore adoption67ddb42
line 479why, one step back479 this.setHeader(key, '' + field[key]);wsTJ Holowaychukbefore adoption858e4dc
lines 480–518why, one step back480 }481 }482 return this;483};484485/**486 * Get value for header `field`.487 *488 * @param {String} field489 * @return {String}490 * @api public491 */492493res.get = function(field){494 return this.getHeader(field);495};496497/**498 * Clear cookie `name`.499 *500 * @param {String} name501 * @param {Object} options502 * @param {ServerResponse} for chaining503 * @api public504 */505506res.clearCookie = function(name, options){507 var opts = { expires: new Date(1), path: '/' };508 return this.cookie(name, '', options509 ? utils.merge(opts, options)510 : opts);511};512513/**514 * Set cookie `name` to `val`, with the given `options`.515 *516 * Options:517 *518 * - `maxAge` max-age in milliseconds, converted to `expires`Added { signed: true } option to res.cookie()TJ Holowaychukbefore adoption1150a88
line 519why, one step back519 * - `signed` sign the cookiewsTJ Holowaychukbefore adoption858e4dc
lines 520–537why, one step back520 * - `path` defaults to "/"521 *522 * Examples:523 *524 * // "Remember Me" for 15 minutes525 * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });526 *527 * // save as above528 * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })529 *530 * @param {String} name531 * @param {String|Object} val532 * @param {Options} options533 * @api public534 */535536res.cookie = function(name, val, options){537 options = options || {};Added { signed: true } option to res.cookie()TJ Holowaychukbefore adoption1150a88
lines 538–540why, one step back538 var secret = this.req.secret;539 var signed = options.signed;540 if (signed && !secret) throw new Error('connect.cookieParser("secret") required for signed cookies');wsTJ Holowaychukbefore adoption858e4dc
line 541why, one step back541 if ('object' == typeof val) val = 'j:' + JSON.stringify(val);Merge pull request #1286 from tnydwrds/fix-signed-cookie-prefixTJ Holowaychukbefore adoption32a5c9c
line 542why, one step back542 if (signed) val = 's:' + utils.sign(val, secret);wsTJ Holowaychukbefore adoption858e4dc
lines 543–544why, one step back543 if ('maxAge' in options) options.expires = new Date(Date.now() + options.maxAge);544 if (null == options.path) options.path = '/';coerce res.cookie values to stringsTJ Holowaychukbefore adoptionebf60d2
line 545why, one step back545 this.set('Set-Cookie', cookie.serialize(name, String(val), options));wsTJ Holowaychukbefore adoption858e4dc
lines 546–601why, one step back546 return this;547};548549/**550 * Redirect to the given `url` with optional response `status`551 * defaulting to 302.552 *553 * The given `url` can also be the name of a mapped url, for554 * example by default express supports "back" which redirects555 * to the _Referrer_ or _Referer_ headers or "/".556 *557 * Examples:558 *559 * res.redirect('/foo/bar');560 * res.redirect('http://example.com');561 * res.redirect(301, 'http://example.com');562 * res.redirect('../login'); // /blog/post/1 -> /blog/login563 *564 * Mounting:565 *566 * When an application is mounted, and `res.redirect()`567 * is given a path that does _not_ lead with "/". For 568 * example suppose a "blog" app is mounted at "/blog",569 * the following redirect would result in "/blog/login":570 *571 * res.redirect('login');572 *573 * While the leading slash would result in a redirect to "/login":574 *575 * res.redirect('/login');576 *577 * @param {String} url578 * @param {Number} code579 * @api public580 */581582res.redirect = function(url){583 var app = this.app584 , req = this.req585 , head = 'HEAD' == req.method586 , status = 302587 , body;588589 // allow status / url590 if (2 == arguments.length) {591 status = url;592 url = arguments[1];593 }594595 // setup redirect map596 var map = { back: req.get('Referrer') || '/' };597598 // perform redirect599 url = map[url] || url;600601 // relativeadd res.redirect("//foo.com") supportTJ Holowaychukbefore adoptiona93d375
line 602why, one step back602 if (!~url.indexOf('://') && 0 != url.indexOf('//')) {wsTJ Holowaychukbefore adoption858e4dc
lines 603–605why, one step back603 var path = app.path();604605 // relative to pathrefactor res.redirect() relative checkTJ Holowaychukbefore adoption362c96c
line 606why, one step back606 if ('.' == url[0]) {wsTJ Holowaychukbefore adoption858e4dc
lines 607–614why, one step back607 url = req.path + '/' + url;608 // relative to mount-point609 } else if ('/' != url[0]) {610 url = path + '/' + url;611 }612613 // Absolute614 var host = req.get('Host');change res.redirect() to use scheme-relative urlsTJ Holowaychukbefore adoptiond66f0e5
line 615why, one step back615 url = '//' + host + url;wsTJ Holowaychukbefore adoption858e4dc
lines 616–624why, one step back616 }617618 // Support text/{plain,html} by default619 this.format({620 text: function(){621 body = statusCodes[status] + '. Redirecting to ' + url;622 },623624 html: function(){escape res.redirect() linkTJ Holowaychukbefore adoptionbac0c64
lines 625–626why, one step back625 var u = utils.escape(url);626 body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>';Added `.default()` support to `res.format()`TJ Holowaychukbefore adoption82b5b12
lines 627–630why, one step back627 },628629 default: function(){630 body = '';wsTJ Holowaychukbefore adoption858e4dc
line 631why, one step back631 }Added `.default()` support to `res.format()`TJ Holowaychukbefore adoption82b5b12
line 632why, one step back632 });wsTJ Holowaychukbefore adoption858e4dc
lines 633–636why, one step back633634 // Respond635 this.statusCode = status;636 this.set('Location', url);Fixed res.redirect() 406. Closes #1154TJ Holowaychukbefore adoption1311f2a
line 637why, one step back637 this.set('Content-Length', Buffer.byteLength(body));wsTJ Holowaychukbefore adoption858e4dc
lines 638–667why, one step back638 this.end(head ? null : body);639};640641/**642 * Render `view` with the given `options` and optional callback `fn`.643 * When a callback function is given a response will _not_ be made644 * automatically, otherwise a response of _200_ and _text/html_ is given.645 *646 * Options:647 *648 * - `cache` boolean hinting to the engine it should cache649 * - `filename` filename of the view being rendered650 *651 * @param {String} view652 * @param {Object|Function} options or callback function653 * @param {Function} fn654 * @api public655 */656657res.render = function(view, options, fn){658 var self = this659 , options = options || {}660 , req = this.req661 , app = req.app;662663 // support callback function as second arg664 if ('function' == typeof options) {665 fn = options, options = {};666 }667remove app.locals.use and res.locals.useTJ Holowaychukbefore adoption4f7c4d1
line 668why, one step back668 // merge res.localsrefactor res.render() to prevent clobbering "locals"TJ Holowaychukbefore adoption6bebe08
line 669why, one step back669 options._locals = self.locals;wsTJ Holowaychukbefore adoption858e4dc
line 670why, one step back670remove app.locals.use and res.locals.useTJ Holowaychukbefore adoption4f7c4d1
lines 671–675why, one step back671 // default callback to respond672 fn = fn || function(err, str){673 if (err) return req.next(err);674 self.send(str);675 };wsTJ Holowaychukbefore adoption858e4dc
line 676why, one step back676remove app.locals.use and res.locals.useTJ Holowaychukbefore adoption4f7c4d1
lines 677–678why, one step back677 // render678 app.render(view, options, fn);wsTJ Holowaychukbefore adoption858e4dc
line 679why, one step back679};