Skip to content
Myr

response.js

This file

Path

lib/response.js

771 lines · 17.5 KiB · JavaScript

Last changed by

res.location: remove resolving relative urlsJonathan Ongbefore adoptionaac1d52

History of this file

Take it

The walk stopped after 200 commits: lines older than 916acd1 point at it.

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 1–7why, one step back
1/**
2 * Module dependencies.3 */45var http = require('http')6 , path = require('path')7 , connect = require('connect')

use utils-merge module to mixin object propertiesRoman Shtylmanbefore adoption718e68f

line 8why, one step back
8 , mixin = require('utils-merge')

use escape-html module to escape htmlRoman Shtylmanbefore adoption63c6a9c

line 9why, one step back
9 , escapeHtml = require('escape-html')

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 10–17why, one step back
10 , sign = require('cookie-signature').sign
11 , normalizeType = require('./utils').normalizeType12 , normalizeTypes = require('./utils').normalizeTypes13 , etag = require('./utils').etag14 , statusCodes = http.STATUS_CODES15 , cookie = require('cookie')16 , send = require('send')17 , mime = connect.mime

Merge pull request #1802 from kapouer/patch-1Jonathan Ongbefore adoption2bc703c

line 18why, one step back
18 , resolve = require('url').resolve

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

line 19why, one step back
19 , basename = path.basename

lint: remove unused stuffJonathan Ongbefore adoption9bed2b8

line 20why, one step back
20 , extname = path.extname;

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 21–58why, one step back
21
22/**23 * Response prototype.24 */2526var res = module.exports = {27 __proto__: http.ServerResponse.prototype28};2930/**31 * Set status `code`.32 *33 * @param {Number} code34 * @return {ServerResponse}35 * @api public36 */3738res.status = function(code){39 this.statusCode = code;40 return this;41};4243/**44 * Set Link header field with the given `links`.45 *46 * Examples:47 *48 * res.links({49 * next: 'http://api.example.com/users?page=2',50 * last: 'http://api.example.com/users?page=5'51 * });52 *53 * @param {Object} links54 * @return {ServerResponse}55 * @api public56 */5758res.links = function(links){

refactor res.links()TJ Holowaychukbefore adoption8e2f538

lines 59–61why, one step back
59 var link = this.get('Link') || '';
60 if (link) link += ', ';61 return this.set('Link', link + Object.keys(links).map(function(rel){

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 62–83why, one step back
62 return '<' + links[rel] + '>; rel="' + rel + '"';
63 }).join(', '));64};6566/**67 * Send a response.68 *69 * Examples:70 *71 * res.send(new Buffer('wahoo'));72 * res.send({ some: 'json' });73 * res.send('<p>some html</p>');74 * res.send(404, 'Sorry, cant find that');75 * res.send(404);76 *77 * @param {Mixed} body or status78 * @param {Mixed} body79 * @return {ServerResponse}80 * @api public81 */8283res.send = function(body){

change generation of ETags with res.send() to GET requests only. Closes #1619TJ Holowaychukbefore adoption3296ed9

lines 84–86why, one step back
84 var req = this.req;
85 var head = 'HEAD' == req.method;86 var len;

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

line 87why, one step back
87

Merge pull request #1694 from kavu/add_disable_etagTJ Holowaychukbefore adoption610e172

lines 88–90why, one step back
88 // settings
89 var app = this.app;90

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 91–136why, one step back
91 // allow status / body
92 if (2 == arguments.length) {93 // res.send(body, status) backwards compat94 if ('number' != typeof body && 'number' == typeof arguments[1]) {95 this.statusCode = arguments[1];96 } else {97 this.statusCode = body;98 body = arguments[1];99 }100 }101102 switch (typeof body) {103 // response status104 case 'number':105 this.get('Content-Type') || this.type('txt');106 this.statusCode = body;107 body = http.STATUS_CODES[body];108 break;109 // string defaulting to html110 case 'string':111 if (!this.get('Content-Type')) {112 this.charset = this.charset || 'utf-8';113 this.type('html');114 }115 break;116 case 'boolean':117 case 'object':118 if (null == body) {119 body = '';120 } else if (Buffer.isBuffer(body)) {121 this.get('Content-Type') || this.type('bin');122 } else {123 return this.json(body);124 }125 break;126 }127128 // populate Content-Length129 if (undefined !== body && !this.get('Content-Length')) {130 this.set('Content-Length', len = Buffer.isBuffer(body)131 ? body.length132 : Buffer.byteLength(body));133 }134135 // ETag support136 // TODO: W/ support

always send ETag when content-length > 0Jonathan Ongbefore adoption55d1a4f

line 137why, one step back
137 if (app.settings.etag && len && 'GET' == req.method) {

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 138–193why, one step back
138 if (!this.get('ETag')) {
139 this.set('ETag', etag(body));140 }141 }142143 // freshness144 if (req.fresh) this.statusCode = 304;145146 // strip irrelevant headers147 if (204 == this.statusCode || 304 == this.statusCode) {148 this.removeHeader('Content-Type');149 this.removeHeader('Content-Length');150 this.removeHeader('Transfer-Encoding');151 body = '';152 }153154 // respond155 this.end(head ? null : body);156 return this;157};158159/**160 * Send JSON response.161 *162 * Examples:163 *164 * res.json(null);165 * res.json({ user: 'tj' });166 * res.json(500, 'oh noes!');167 * res.json(404, 'I dont have that');168 *169 * @param {Mixed} obj or status170 * @param {Mixed} obj171 * @return {ServerResponse}172 * @api public173 */174175res.json = function(obj){176 // allow status / body177 if (2 == arguments.length) {178 // res.json(body, status) backwards compat179 if ('number' == typeof arguments[1]) {180 this.statusCode = arguments[1];181 } else {182 this.statusCode = obj;183 obj = arguments[1];184 }185 }186187 // settings188 var app = this.app;189 var replacer = app.get('json replacer');190 var spaces = app.get('json spaces');191 var body = JSON.stringify(obj, replacer, spaces);192193 // content-type

Revert "remove charset from json responses. Closes #1631"TJ Holowaychukbefore adoption6cf6c8b

line 194why, one step back
194 this.charset = this.charset || 'utf-8';

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 195–242why, one step back
195 this.get('Content-Type') || this.set('Content-Type', 'application/json');
196197 return this.send(body);198};199200/**201 * Send JSON response with JSONP callback support.202 *203 * Examples:204 *205 * res.jsonp(null);206 * res.jsonp({ user: 'tj' });207 * res.jsonp(500, 'oh noes!');208 * res.jsonp(404, 'I dont have that');209 *210 * @param {Mixed} obj or status211 * @param {Mixed} obj212 * @return {ServerResponse}213 * @api public214 */215216res.jsonp = function(obj){217 // allow status / body218 if (2 == arguments.length) {219 // res.json(body, status) backwards compat220 if ('number' == typeof arguments[1]) {221 this.statusCode = arguments[1];222 } else {223 this.statusCode = obj;224 obj = arguments[1];225 }226 }227228 // settings229 var app = this.app;230 var replacer = app.get('json replacer');231 var spaces = app.get('json spaces');232 var body = JSON.stringify(obj, replacer, spaces)233 .replace(/\u2028/g, '\\u2028')234 .replace(/\u2029/g, '\\u2029');235 var callback = this.req.query[app.get('jsonp callback name')];236237 // content-type238 this.charset = this.charset || 'utf-8';239 this.set('Content-Type', 'application/json');240241 // jsonp242 if (callback) {

Merge pull request #1711 from jonjenkins/masterTJ Holowaychukbefore adoption3ea7381

line 243why, one step back
243 if (Array.isArray(callback)) callback = callback[0];

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 244–245why, one step back
244 this.set('Content-Type', 'text/javascript');
245 var cb = callback.replace(/[^\[\]\w$.]/g, '');

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoptionbd8b9f5

line 246why, one step back
246 body = 'typeof ' + cb + ' === \'function\' && ' + cb + '(' + body + ');';

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 247–327why, one step back
247 }
248249 return this.send(body);250};251252/**253 * Transfer the file at the given `path`.254 *255 * Automatically sets the _Content-Type_ response header field.256 * The callback `fn(err)` is invoked when the transfer is complete257 * or when an error occurs. Be sure to check `res.sentHeader`258 * if you wish to attempt responding, as the header and some data259 * may have already been transferred.260 *261 * Options:262 *263 * - `maxAge` defaulting to 0264 * - `root` root directory for relative filenames265 *266 * Examples:267 *268 * The following example illustrates how `res.sendfile()` may269 * be used as an alternative for the `static()` middleware for270 * dynamic situations. The code backing `res.sendfile()` is actually271 * the same code, so HTTP cache support etc is identical.272 *273 * app.get('/user/:uid/photos/:file', function(req, res){274 * var uid = req.params.uid275 * , file = req.params.file;276 *277 * req.user.mayViewFilesFrom(uid, function(yes){278 * if (yes) {279 * res.sendfile('/uploads/' + uid + '/' + file);280 * } else {281 * res.send(403, 'Sorry! you cant see that.');282 * }283 * });284 * });285 *286 * @param {String} path287 * @param {Object|Function} options or fn288 * @param {Function} fn289 * @api public290 */291292res.sendfile = function(path, options, fn){293 var self = this294 , req = self.req295 , next = this.req.next296 , options = options || {}297 , done;298299 // support function as second arg300 if ('function' == typeof options) {301 fn = options;302 options = {};303 }304305 // socket errors306 req.socket.on('error', error);307308 // errors309 function error(err) {310 if (done) return;311 done = true;312313 // clean up314 cleanup();315 if (!self.headerSent) self.removeHeader('Content-Disposition');316317 // callback available318 if (fn) return fn(err);319320 // list in limbo if there's no callback321 if (self.headerSent) return;322323 // delegate324 next(err);325 }326327 // streaming

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption0b88208

line 328why, one step back
328 function stream(stream) {

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 329–330why, one step back
329 if (done) return;
330 cleanup();

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption0b88208

line 331why, one step back
331 if (fn) stream.on('end', fn);

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 332–468why, one step back
332 }
333334 // cleanup335 function cleanup() {336 req.socket.removeListener('error', error);337 }338339 // transfer340 var file = send(req, path);341 if (options.root) file.root(options.root);342 file.maxage(options.maxAge || 0);343 file.on('error', error);344 file.on('directory', next);345 file.on('stream', stream);346 file.pipe(this);347 this.on('finish', cleanup);348};349350/**351 * Transfer the file at the given `path` as an attachment.352 *353 * Optionally providing an alternate attachment `filename`,354 * and optional callback `fn(err)`. The callback is invoked355 * when the data transfer is complete, or when an error has356 * ocurred. Be sure to check `res.headerSent` if you plan to respond.357 *358 * This method uses `res.sendfile()`.359 *360 * @param {String} path361 * @param {String|Function} filename or fn362 * @param {Function} fn363 * @api public364 */365366res.download = function(path, filename, fn){367 // support function as second arg368 if ('function' == typeof filename) {369 fn = filename;370 filename = null;371 }372373 filename = filename || path;374 this.set('Content-Disposition', 'attachment; filename="' + basename(filename) + '"');375 return this.sendfile(path, fn);376};377378/**379 * Set _Content-Type_ response header with `type` through `mime.lookup()`380 * when it does not contain "/", or set the Content-Type to `type` otherwise.381 *382 * Examples:383 *384 * res.type('.html');385 * res.type('html');386 * res.type('json');387 * res.type('application/json');388 * res.type('png');389 *390 * @param {String} type391 * @return {ServerResponse} for chaining392 * @api public393 */394395res.contentType =396res.type = function(type){397 return this.set('Content-Type', ~type.indexOf('/')398 ? type399 : mime.lookup(type));400};401402/**403 * Respond to the Acceptable formats using an `obj`404 * of mime-type callbacks.405 *406 * This method uses `req.accepted`, an array of407 * acceptable types ordered by their quality values.408 * When "Accept" is not present the _first_ callback409 * is invoked, otherwise the first match is used. When410 * no match is performed the server responds with411 * 406 "Not Acceptable".412 *413 * Content-Type is set for you, however if you choose414 * you may alter this within the callback using `res.type()`415 * or `res.set('Content-Type', ...)`.416 *417 * res.format({418 * 'text/plain': function(){419 * res.send('hey');420 * },421 *422 * 'text/html': function(){423 * res.send('<p>hey</p>');424 * },425 *426 * 'appliation/json': function(){427 * res.send({ message: 'hey' });428 * }429 * });430 *431 * In addition to canonicalized MIME types you may432 * also use extnames mapped to these types:433 *434 * res.format({435 * text: function(){436 * res.send('hey');437 * },438 *439 * html: function(){440 * res.send('<p>hey</p>');441 * },442 *443 * json: function(){444 * res.send({ message: 'hey' });445 * }446 * });447 *448 * By default Express passes an `Error`449 * with a `.status` of 406 to `next(err)`450 * if a match is not made. If you provide451 * a `.default` callback it will be invoked452 * instead.453 *454 * @param {Object} obj455 * @return {ServerResponse} for chaining456 * @api public457 */458459res.format = function(obj){460 var req = this.req461 , next = req.next;462463 var fn = obj.default;464 if (fn) delete obj.default;465 var keys = Object.keys(obj);466467 var key = req.accepts(keys);468

add res.vary(). Closes #1682cjihrigbefore adoptione5de08f

line 469why, one step back
469 this.vary("Accept");

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 470–471why, one step back
470
471 if (key) {

Merge pull request #1747 from sorribas/masterTJ Holowaychukbefore adoption1c87e5e

lines 472–473why, one step back
472 var type = normalizeType(key).value;
473 var charset = mime.charsets.lookup(type);

refactor res.format() with a little ocdTJ Holowaychukbefore adoption3b4ce91

line 474why, one step back
474 if (charset) type += '; charset=' + charset;

Merge pull request #1747 from sorribas/masterTJ Holowaychukbefore adoption1c87e5e

line 475why, one step back
475 this.set('Content-Type', type);

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 476–481why, one step back
476 obj[key](req, this, next);
477 } else if (fn) {478 fn();479 } else {480 var err = new Error('Not Acceptable');481 err.status = 406;

add support for custom Accept parametersPavel Brylovbefore adoption9e684d4

line 482why, one step back
482 err.types = normalizeTypes(keys).map(function(o){ return o.value });

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 483–560why, one step back
483 next(err);
484 }485486 return this;487};488489/**490 * Set _Content-Disposition_ header to _attachment_ with optional `filename`.491 *492 * @param {String} filename493 * @return {ServerResponse}494 * @api public495 */496497res.attachment = function(filename){498 if (filename) this.type(extname(filename));499 this.set('Content-Disposition', filename500 ? 'attachment; filename="' + basename(filename) + '"'501 : 'attachment');502 return this;503};504505/**506 * Set header `field` to `val`, or pass507 * an object of header fields.508 *509 * Examples:510 *511 * res.set('Foo', ['bar', 'baz']);512 * res.set('Accept', 'application/json');513 * res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });514 *515 * Aliased as `res.header()`.516 *517 * @param {String|Object|Array} field518 * @param {String} val519 * @return {ServerResponse} for chaining520 * @api public521 */522523res.set =524res.header = function(field, val){525 if (2 == arguments.length) {526 if (Array.isArray(val)) val = val.map(String);527 else val = String(val);528 this.setHeader(field, val);529 } else {530 for (var key in field) {531 this.set(key, field[key]);532 }533 }534 return this;535};536537/**538 * Get value for header `field`.539 *540 * @param {String} field541 * @return {String}542 * @api public543 */544545res.get = function(field){546 return this.getHeader(field);547};548549/**550 * Clear cookie `name`.551 *552 * @param {String} name553 * @param {Object} options554 * @param {ServerResponse} for chaining555 * @api public556 */557558res.clearCookie = function(name, options){559 var opts = { expires: new Date(1), path: '/' };560 return this.cookie(name, '', options

use utils-merge module to mixin object propertiesRoman Shtylmanbefore adoption718e68f

line 561why, one step back
561 ? mixin(opts, options)

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 562–588why, one step back
562 : opts);
563};564565/**566 * Set cookie `name` to `val`, with the given `options`.567 *568 * Options:569 *570 * - `maxAge` max-age in milliseconds, converted to `expires`571 * - `signed` sign the cookie572 * - `path` defaults to "/"573 *574 * Examples:575 *576 * // "Remember Me" for 15 minutes577 * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });578 *579 * // save as above580 * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })581 *582 * @param {String} name583 * @param {String|Object} val584 * @param {Options} options585 * @api public586 */587588res.cookie = function(name, val, options){

use utils-merge module to mixin object propertiesRoman Shtylmanbefore adoption718e68f

line 589why, one step back
589 options = mixin({}, options);

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 590–592why, one step back
590 var secret = this.req.secret;
591 var signed = options.signed;592 if (signed && !secret) throw new Error('connect.cookieParser("secret") required for signed cookies');

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoptionea2664a

line 593why, one step back
593 if ('number' == typeof val) val = val.toString();

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 594–608why, one step back
594 if ('object' == typeof val) val = 'j:' + JSON.stringify(val);
595 if (signed) val = 's:' + sign(val, secret);596 if ('maxAge' in options) {597 options.expires = new Date(Date.now() + options.maxAge);598 options.maxAge /= 1000;599 }600 if (null == options.path) options.path = '/';601 this.set('Set-Cookie', cookie.serialize(name, String(val), options));602 return this;603};604605606/**607 * Set the location header to `url`.608 *

Merge pull request #1829 from michaelficarra/patch-1TJ Holowaychukbefore adoptionde54af4

line 609why, one step back
609 * The given `url` can also be "back", which redirects

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 610–615why, one step back
610 * to the _Referrer_ or _Referer_ headers or "/".
611 *612 * Examples:613 *614 * res.location('/foo/bar').;615 * res.location('http://example.com');

res.location: remove resolving relative urlsJonathan Ongbefore adoptionaac1d52

line 616why, one step back
616 * res.location('../login');

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 617–622why, one step back
617 *
618 * @param {String} url619 * @api public620 */621622res.location = function(url){

res.location: remove resolving relative urlsJonathan Ongbefore adoptionaac1d52

line 623why, one step back
623 var req = this.req;

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

line 624why, one step back
624

Merge pull request #1829 from michaelficarra/patch-1TJ Holowaychukbefore adoptionde54af4

line 625why, one step back
625 // "back" is an alias for the referrer

ocdTJ Holowaychukbefore adoption8a7a695

line 626why, one step back
626 if ('back' == url) url = req.get('Referrer') || '/';

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 627–654why, one step back
627
628 // Respond629 this.set('Location', url);630 return this;631};632633/**634 * Redirect to the given `url` with optional response `status`635 * defaulting to 302.636 *637 * The resulting `url` is determined by `res.location()`, so638 * it will play nicely with mounted apps, relative paths,639 * `"back"` etc.640 *641 * Examples:642 *643 * res.redirect('/foo/bar');644 * res.redirect('http://example.com');645 * res.redirect(301, 'http://example.com');646 * res.redirect('http://example.com', 301);647 * res.redirect('../login'); // /blog/post/1 -> /blog/login648 *649 * @param {String} url650 * @param {Number} code651 * @api public652 */653654res.redirect = function(url){

lint: remove unused stuffJonathan Ongbefore adoption9bed2b8

line 655why, one step back
655 var head = 'HEAD' == this.req.method

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 656–679why, one step back
656 , status = 302
657 , body;658659 // allow status / url660 if (2 == arguments.length) {661 if ('number' == typeof url) {662 status = url;663 url = arguments[1];664 } else {665 status = arguments[1];666 }667 }668669 // Set location header670 this.location(url);671 url = this.get('Location');672673 // Support text/{plain,html} by default674 this.format({675 text: function(){676 body = statusCodes[status] + '. Redirecting to ' + encodeURI(url);677 },678679 html: function(){

use escape-html module to escape htmlRoman Shtylmanbefore adoption63c6a9c

line 680why, one step back
680 var u = escapeHtml(url);

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 681–692why, one step back
681 body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>';
682 },683684 default: function(){685 body = '';686 }687 });688689 // Respond690 this.statusCode = status;691 this.set('Content-Length', Buffer.byteLength(body));692 this.end(head ? null : body);

add res.vary(). Closes #1682cjihrigbefore adoptione5de08f

lines 693–719why, one step back
693};
694695/**696 * Add `field` to Vary. If already present in the Vary set, then697 * this call is simply ignored.698 *699 * @param {Array|String} field700 * @param {ServerResponse} for chaining701 * @api public702 */703704res.vary = function(field){705 var self = this;706707 // nothing708 if (!field) return this;709710 // array711 if (Array.isArray(field)) {712 field.forEach(function(field){713 self.vary(field);714 });715 return;716 }717718 var vary = this.get('Vary');719

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoptionbd8b9f5

line 720why, one step back
720 // append

add res.vary(). Closes #1682cjihrigbefore adoptione5de08f

lines 721–730why, one step back
721 if (vary) {
722 vary = vary.split(/ *, */);723 if (!~vary.indexOf(field)) vary.push(field);724 this.set('Vary', vary.join(', '));725 return this;726 }727728 // set729 this.set('Vary', field);730 return this;

replace 0.6.x travis with 0.10.xTJ Holowaychukbefore adoption916acd1

lines 731–771why, one step back
731};
732733/**734 * Render `view` with the given `options` and optional callback `fn`.735 * When a callback function is given a response will _not_ be made736 * automatically, otherwise a response of _200_ and _text/html_ is given.737 *738 * Options:739 *740 * - `cache` boolean hinting to the engine it should cache741 * - `filename` filename of the view being rendered742 *743 * @param {String} view744 * @param {Object|Function} options or callback function745 * @param {Function} fn746 * @api public747 */748749res.render = function(view, options, fn){750 var self = this751 , options = options || {}752 , req = this.req753 , app = req.app;754755 // support callback function as second arg756 if ('function' == typeof options) {757 fn = options, options = {};758 }759760 // merge res.locals761 options._locals = self.locals;762763 // default callback to respond764 fn = fn || function(err, str){765 if (err) return req.next(err);766 self.send(str);767 };768769 // render770 app.render(view, options, fn);771};