response.js
This file
Path
lib/response.js
785 lines · 17.9 KiB · JavaScript
Last changed by
move setHeader charset patch to .setJonathan Ongbefore adoptionbad55f7
History of this fileTake it
The walk stopped after 200 commits: lines older than 58f2057 point at it.
revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 1–4why, one step back1/**2 * Module dependencies.3 */4move setHeader charset patch to .setJonathan Ongbefore adoptionbad55f7
lines 5–18why, one step back5var http = require('http');6var path = require('path');7var mixin = require('utils-merge');8var escapeHtml = require('escape-html');9var sign = require('cookie-signature').sign;10var normalizeType = require('./utils').normalizeType;11var normalizeTypes = require('./utils').normalizeTypes;12var etag = require('./utils').etag;13var statusCodes = http.STATUS_CODES;14var cookie = require('cookie');15var send = require('send');16var basename = path.basename;17var extname = path.extname;18var mime = send.mime;revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 19–56why, one step back1920/**21 * Response prototype.22 */2324var res = module.exports = {25 __proto__: http.ServerResponse.prototype26};2728/**29 * Set status `code`.30 *31 * @param {Number} code32 * @return {ServerResponse}33 * @api public34 */3536res.status = function(code){37 this.statusCode = code;38 return this;39};4041/**42 * Set Link header field with the given `links`.43 *44 * Examples:45 *46 * res.links({47 * next: 'http://api.example.com/users?page=2',48 * last: 'http://api.example.com/users?page=5'49 * });50 *51 * @param {Object} links52 * @return {ServerResponse}53 * @api public54 */5556res.links = function(links){refactor res.links()TJ Holowaychukbefore adoption8e2f538
lines 57–59why, one step back57 var link = this.get('Link') || '';58 if (link) link += ', ';59 return this.set('Link', link + Object.keys(links).map(function(rel){revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 60–81why, one step back60 return '<' + links[rel] + '>; rel="' + rel + '"';61 }).join(', '));62};6364/**65 * Send a response.66 *67 * Examples:68 *69 * res.send(new Buffer('wahoo'));70 * res.send({ some: 'json' });71 * res.send('<p>some html</p>');72 * res.send(404, 'Sorry, cant find that');73 * res.send(404);74 *75 * @param {Mixed} body or status76 * @param {Mixed} body77 * @return {ServerResponse}78 * @api public79 */8081res.send = function(body){change generation of ETags with res.send() to GET requests only. Closes #1619TJ Holowaychukbefore adoption3296ed9
lines 82–84why, one step back82 var req = this.req;83 var head = 'HEAD' == req.method;84 var len;revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
line 85why, one step back85Merge pull request #1694 from kavu/add_disable_etagTJ Holowaychukbefore adoption610e172
lines 86–88why, one step back86 // settings87 var app = this.app;88revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 89–134why, one step back89 // allow status / body90 if (2 == arguments.length) {91 // res.send(body, status) backwards compat92 if ('number' != typeof body && 'number' == typeof arguments[1]) {93 this.statusCode = arguments[1];94 } else {95 this.statusCode = body;96 body = arguments[1];97 }98 }99100 switch (typeof body) {101 // response status102 case 'number':103 this.get('Content-Type') || this.type('txt');104 this.statusCode = body;105 body = http.STATUS_CODES[body];106 break;107 // string defaulting to html108 case 'string':109 if (!this.get('Content-Type')) {110 this.charset = this.charset || 'utf-8';111 this.type('html');112 }113 break;114 case 'boolean':115 case 'object':116 if (null == body) {117 body = '';118 } else if (Buffer.isBuffer(body)) {119 this.get('Content-Type') || this.type('bin');120 } else {121 return this.json(body);122 }123 break;124 }125126 // populate Content-Length127 if (undefined !== body && !this.get('Content-Length')) {128 this.set('Content-Length', len = Buffer.isBuffer(body)129 ? body.length130 : Buffer.byteLength(body));131 }132133 // ETag support134 // TODO: W/ supportalways send ETag when content-length > 0Jonathan Ongbefore adoption55d1a4f
line 135why, one step back135 if (app.settings.etag && len && 'GET' == req.method) {revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 136–191why, one step back136 if (!this.get('ETag')) {137 this.set('ETag', etag(body));138 }139 }140141 // freshness142 if (req.fresh) this.statusCode = 304;143144 // strip irrelevant headers145 if (204 == this.statusCode || 304 == this.statusCode) {146 this.removeHeader('Content-Type');147 this.removeHeader('Content-Length');148 this.removeHeader('Transfer-Encoding');149 body = '';150 }151152 // respond153 this.end(head ? null : body);154 return this;155};156157/**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) {176 // 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 }183 }184185 // settings186 var app = this.app;187 var replacer = app.get('json replacer');188 var spaces = app.get('json spaces');189 var body = JSON.stringify(obj, replacer, spaces);190191 // content-typeRevert "remove charset from json responses. Closes #1631"TJ Holowaychukbefore adoption6cf6c8b
line 192why, one step back192 this.charset = this.charset || 'utf-8';revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 193–240why, one step back193 this.get('Content-Type') || this.set('Content-Type', 'application/json');194195 return this.send(body);196};197198/**199 * Send JSON response with JSONP callback support.200 *201 * Examples:202 *203 * res.jsonp(null);204 * res.jsonp({ user: 'tj' });205 * res.jsonp(500, 'oh noes!');206 * res.jsonp(404, 'I dont have that');207 *208 * @param {Mixed} obj or status209 * @param {Mixed} obj210 * @return {ServerResponse}211 * @api public212 */213214res.jsonp = function(obj){215 // allow status / body216 if (2 == arguments.length) {217 // res.json(body, status) backwards compat218 if ('number' == typeof arguments[1]) {219 this.statusCode = arguments[1];220 } else {221 this.statusCode = obj;222 obj = arguments[1];223 }224 }225226 // settings227 var app = this.app;228 var replacer = app.get('json replacer');229 var spaces = app.get('json spaces');230 var body = JSON.stringify(obj, replacer, spaces)231 .replace(/\u2028/g, '\\u2028')232 .replace(/\u2029/g, '\\u2029');233 var callback = this.req.query[app.get('jsonp callback name')];234235 // content-type236 this.charset = this.charset || 'utf-8';237 this.set('Content-Type', 'application/json');238239 // jsonp240 if (callback) {Merge pull request #1711 from jonjenkins/masterTJ Holowaychukbefore adoption3ea7381
line 241why, one step back241 if (Array.isArray(callback)) callback = callback[0];revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 242–243why, one step back242 this.set('Content-Type', 'text/javascript');243 var cb = callback.replace(/[^\[\]\w$.]/g, '');Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoptionbd8b9f5
line 244why, one step back244 body = 'typeof ' + cb + ' === \'function\' && ' + cb + '(' + body + ');';revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 245–312why, one step back245 }246247 return this.send(body);248};249250/**251 * Transfer the file at the given `path`.252 *253 * Automatically sets the _Content-Type_ response header field.254 * The callback `fn(err)` is invoked when the transfer is complete255 * or when an error occurs. Be sure to check `res.sentHeader`256 * if you wish to attempt responding, as the header and some data257 * may have already been transferred.258 *259 * Options:260 *261 * - `maxAge` defaulting to 0262 * - `root` root directory for relative filenames263 *264 * Examples:265 *266 * The following example illustrates how `res.sendfile()` may267 * be used as an alternative for the `static()` middleware for268 * dynamic situations. The code backing `res.sendfile()` is actually269 * the same code, so HTTP cache support etc is identical.270 *271 * app.get('/user/:uid/photos/:file', function(req, res){272 * var uid = req.params.uid273 * , file = req.params.file;274 *275 * req.user.mayViewFilesFrom(uid, function(yes){276 * if (yes) {277 * res.sendfile('/uploads/' + uid + '/' + file);278 * } else {279 * res.send(403, 'Sorry! you cant see that.');280 * }281 * });282 * });283 *284 * @param {String} path285 * @param {Object|Function} options or fn286 * @param {Function} fn287 * @api public288 */289290res.sendfile = function(path, options, fn){291 var self = this292 , req = self.req293 , next = this.req.next294 , options = options || {}295 , done;296297 // support function as second arg298 if ('function' == typeof options) {299 fn = options;300 options = {};301 }302303 // socket errors304 req.socket.on('error', error);305306 // errors307 function error(err) {308 if (done) return;309 done = true;310311 // clean up312 cleanup();remove ServerResonse.headerSent monkey patchRoman Shtylmanbefore adoption6835289
line 313why, one step back313 if (!self.headersSent) self.removeHeader('Content-Disposition');revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 314–318why, one step back314315 // callback available316 if (fn) return fn(err);317318 // list in limbo if there's no callbackremove ServerResonse.headerSent monkey patchRoman Shtylmanbefore adoption6835289
line 319why, one step back319 if (self.headersSent) return;revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 320–325why, one step back320321 // delegate322 next(err);323 }324325 // streamingMerge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption0b88208
line 326why, one step back326 function stream(stream) {revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 327–328why, one step back327 if (done) return;328 cleanup();Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption0b88208
line 329why, one step back329 if (fn) stream.on('end', fn);revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 330–353why, one step back330 }331332 // cleanup333 function cleanup() {334 req.socket.removeListener('error', error);335 }336337 // transfer338 var file = send(req, path);339 if (options.root) file.root(options.root);340 file.maxage(options.maxAge || 0);341 file.on('error', error);342 file.on('directory', next);343 file.on('stream', stream);344 file.pipe(this);345 this.on('finish', cleanup);346};347348/**349 * Transfer the file at the given `path` as an attachment.350 *351 * Optionally providing an alternate attachment `filename`,352 * and optional callback `fn(err)`. The callback is invoked353 * when the data transfer is complete, or when an error hasremove ServerResonse.headerSent monkey patchRoman Shtylmanbefore adoption6835289
line 354why, one step back354 * ocurred. Be sure to check `res.headersSent` if you plan to respond.revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 355–466why, one step back355 *356 * This method uses `res.sendfile()`.357 *358 * @param {String} path359 * @param {String|Function} filename or fn360 * @param {Function} fn361 * @api public362 */363364res.download = function(path, filename, fn){365 // support function as second arg366 if ('function' == typeof filename) {367 fn = filename;368 filename = null;369 }370371 filename = filename || path;372 this.set('Content-Disposition', 'attachment; filename="' + basename(filename) + '"');373 return this.sendfile(path, fn);374};375376/**377 * Set _Content-Type_ response header with `type` through `mime.lookup()`378 * when it does not contain "/", or set the Content-Type to `type` otherwise.379 *380 * Examples:381 *382 * res.type('.html');383 * res.type('html');384 * res.type('json');385 * res.type('application/json');386 * res.type('png');387 *388 * @param {String} type389 * @return {ServerResponse} for chaining390 * @api public391 */392393res.contentType =394res.type = function(type){395 return this.set('Content-Type', ~type.indexOf('/')396 ? type397 : mime.lookup(type));398};399400/**401 * Respond to the Acceptable formats using an `obj`402 * of mime-type callbacks.403 *404 * This method uses `req.accepted`, an array of405 * acceptable types ordered by their quality values.406 * When "Accept" is not present the _first_ callback407 * is invoked, otherwise the first match is used. When408 * no match is performed the server responds with409 * 406 "Not Acceptable".410 *411 * Content-Type is set for you, however if you choose412 * you may alter this within the callback using `res.type()`413 * or `res.set('Content-Type', ...)`.414 *415 * res.format({416 * 'text/plain': function(){417 * res.send('hey');418 * },419 *420 * 'text/html': function(){421 * res.send('<p>hey</p>');422 * },423 *424 * 'appliation/json': function(){425 * res.send({ message: 'hey' });426 * }427 * });428 *429 * In addition to canonicalized MIME types you may430 * also use extnames mapped to these types:431 *432 * res.format({433 * text: function(){434 * res.send('hey');435 * },436 *437 * html: function(){438 * res.send('<p>hey</p>');439 * },440 *441 * json: function(){442 * res.send({ message: 'hey' });443 * }444 * });445 *446 * By default Express passes an `Error`447 * with a `.status` of 406 to `next(err)`448 * if a match is not made. If you provide449 * a `.default` callback it will be invoked450 * instead.451 *452 * @param {Object} obj453 * @return {ServerResponse} for chaining454 * @api public455 */456457res.format = function(obj){458 var req = this.req459 , next = req.next;460461 var fn = obj.default;462 if (fn) delete obj.default;463 var keys = Object.keys(obj);464465 var key = req.accepts(keys);466add res.vary(). Closes #1682cjihrigbefore adoptione5de08f
line 467why, one step back467 this.vary("Accept");revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 468–469why, one step back468469 if (key) {Merge pull request #1747 from sorribas/masterTJ Holowaychukbefore adoption1c87e5e
lines 470–471why, one step back470 var type = normalizeType(key).value;471 var charset = mime.charsets.lookup(type);refactor res.format() with a little ocdTJ Holowaychukbefore adoption3b4ce91
line 472why, one step back472 if (charset) type += '; charset=' + charset;Merge pull request #1747 from sorribas/masterTJ Holowaychukbefore adoption1c87e5e
line 473why, one step back473 this.set('Content-Type', type);revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 474–525why, one step back474 obj[key](req, this, next);475 } else if (fn) {476 fn();477 } else {478 var err = new Error('Not Acceptable');479 err.status = 406;480 err.types = normalizeTypes(keys).map(function(o){ return o.value });481 next(err);482 }483484 return this;485};486487/**488 * Set _Content-Disposition_ header to _attachment_ with optional `filename`.489 *490 * @param {String} filename491 * @return {ServerResponse}492 * @api public493 */494495res.attachment = function(filename){496 if (filename) this.type(extname(filename));497 this.set('Content-Disposition', filename498 ? 'attachment; filename="' + basename(filename) + '"'499 : 'attachment');500 return this;501};502503/**504 * Set header `field` to `val`, or pass505 * an object of header fields.506 *507 * Examples:508 *509 * res.set('Foo', ['bar', 'baz']);510 * res.set('Accept', 'application/json');511 * res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });512 *513 * Aliased as `res.header()`.514 *515 * @param {String|Object|Array} field516 * @param {String} val517 * @return {ServerResponse} for chaining518 * @api public519 */520521res.set =522res.header = function(field, val){523 if (2 == arguments.length) {524 if (Array.isArray(val)) val = val.map(String);525 else val = String(val);move setHeader charset patch to .setJonathan Ongbefore adoptionbad55f7
lines 526–530why, one step back526 field = field.toLowerCase();527 if ('content-type' == field && !/;\s*charset\s*=/.test(val)) {528 var charset = mime.charsets.lookup(val.split(';')[0]);529 if (charset) val += '; charset=' + charset.toLowerCase();530 }revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 531–563why, one step back531 this.setHeader(field, val);532 } else {533 for (var key in field) {534 this.set(key, field[key]);535 }536 }537 return this;538};539540/**541 * Get value for header `field`.542 *543 * @param {String} field544 * @return {String}545 * @api public546 */547548res.get = function(field){549 return this.getHeader(field);550};551552/**553 * Clear cookie `name`.554 *555 * @param {String} name556 * @param {Object} options557 * @param {ServerResponse} for chaining558 * @api public559 */560561res.clearCookie = function(name, options){562 var opts = { expires: new Date(1), path: '/' };563 return this.cookie(name, '', optionsuse utils-merge module to mixin object propertiesRoman Shtylmanbefore adoption718e68f
line 564why, one step back564 ? mixin(opts, options)revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 565–591why, one step back565 : opts);566};567568/**569 * Set cookie `name` to `val`, with the given `options`.570 *571 * Options:572 *573 * - `maxAge` max-age in milliseconds, converted to `expires`574 * - `signed` sign the cookie575 * - `path` defaults to "/"576 *577 * Examples:578 *579 * // "Remember Me" for 15 minutes580 * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });581 *582 * // save as above583 * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })584 *585 * @param {String} name586 * @param {String|Object} val587 * @param {Options} options588 * @api public589 */590591res.cookie = function(name, val, options){use utils-merge module to mixin object propertiesRoman Shtylmanbefore adoption718e68f
line 592why, one step back592 options = mixin({}, options);revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 593–594why, one step back593 var secret = this.req.secret;594 var signed = options.signed;remove last pieces of connect dependencyRoman Shtylmanbefore adoption1396e08
line 595why, one step back595 if (signed && !secret) throw new Error('cookieParser("secret") required for signed cookies');Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoptionea2664a
line 596why, one step back596 if ('number' == typeof val) val = val.toString();revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 597–603why, one step back597 if ('object' == typeof val) val = 'j:' + JSON.stringify(val);598 if (signed) val = 's:' + sign(val, secret);599 if ('maxAge' in options) {600 options.expires = new Date(Date.now() + options.maxAge);601 options.maxAge /= 1000;602 }603 if (null == options.path) options.path = '/';move support for multiple `res.cookie` calls to lib/responseRoman Shtylmanbefore adoptiond42d8f5
lines 604–615why, one step back604 var headerVal = cookie.serialize(name, String(val), options);605606 // supports multiple 'res.cookie' calls by getting previous value607 var prev = this.get('Set-Cookie');608 if (prev) {609 if (Array.isArray(prev)) {610 headerVal = prev.concat(headerVal);611 } else {612 headerVal = [prev, headerVal];613 }614 }615 this.set('Set-Cookie', headerVal);revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 616–622why, one step back616 return this;617};618619620/**621 * Set the location header to `url`.622 *Merge pull request #1829 from michaelficarra/patch-1TJ Holowaychukbefore adoptionde54af4
line 623why, one step back623 * The given `url` can also be "back", which redirectsrevert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 624–629why, one step back624 * to the _Referrer_ or _Referer_ headers or "/".625 *626 * Examples:627 *628 * res.location('/foo/bar').;629 * res.location('http://example.com');res.location: remove resolving relative urlsJonathan Ongbefore adoptionaac1d52
line 630why, one step back630 * res.location('../login');revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 631–636why, one step back631 *632 * @param {String} url633 * @api public634 */635636res.location = function(url){res.location: remove resolving relative urlsJonathan Ongbefore adoptionaac1d52
line 637why, one step back637 var req = this.req;revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
line 638why, one step back638Merge pull request #1829 from michaelficarra/patch-1TJ Holowaychukbefore adoptionde54af4
line 639why, one step back639 // "back" is an alias for the referrerocdTJ Holowaychukbefore adoption8a7a695
line 640why, one step back640 if ('back' == url) url = req.get('Referrer') || '/';revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 641–668why, one step back641642 // Respond643 this.set('Location', url);644 return this;645};646647/**648 * Redirect to the given `url` with optional response `status`649 * defaulting to 302.650 *651 * The resulting `url` is determined by `res.location()`, so652 * it will play nicely with mounted apps, relative paths,653 * `"back"` etc.654 *655 * Examples:656 *657 * res.redirect('/foo/bar');658 * res.redirect('http://example.com');659 * res.redirect(301, 'http://example.com');660 * res.redirect('http://example.com', 301);661 * res.redirect('../login'); // /blog/post/1 -> /blog/login662 *663 * @param {String} url664 * @param {Number} code665 * @api public666 */667668res.redirect = function(url){lint: remove unused stuffJonathan Ongbefore adoption9bed2b8
line 669why, one step back669 var head = 'HEAD' == this.req.methodrevert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 670–693why, one step back670 , status = 302671 , body;672673 // allow status / url674 if (2 == arguments.length) {675 if ('number' == typeof url) {676 status = url;677 url = arguments[1];678 } else {679 status = arguments[1];680 }681 }682683 // Set location header684 this.location(url);685 url = this.get('Location');686687 // Support text/{plain,html} by default688 this.format({689 text: function(){690 body = statusCodes[status] + '. Redirecting to ' + encodeURI(url);691 },692693 html: function(){use escape-html module to escape htmlRoman Shtylmanbefore adoption63c6a9c
line 694why, one step back694 var u = escapeHtml(url);revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 695–706why, one step back695 body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>';696 },697698 default: function(){699 body = '';700 }701 });702703 // Respond704 this.statusCode = status;705 this.set('Content-Length', Buffer.byteLength(body));706 this.end(head ? null : body);add res.vary(). Closes #1682cjihrigbefore adoptione5de08f
lines 707–733why, one step back707};708709/**710 * Add `field` to Vary. If already present in the Vary set, then711 * this call is simply ignored.712 *713 * @param {Array|String} field714 * @param {ServerResponse} for chaining715 * @api public716 */717718res.vary = function(field){719 var self = this;720721 // nothing722 if (!field) return this;723724 // array725 if (Array.isArray(field)) {726 field.forEach(function(field){727 self.vary(field);728 });729 return;730 }731732 var vary = this.get('Vary');733Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoptionbd8b9f5
line 734why, one step back734 // appendadd res.vary(). Closes #1682cjihrigbefore adoptione5de08f
lines 735–744why, one step back735 if (vary) {736 vary = vary.split(/ *, */);737 if (!~vary.indexOf(field)) vary.push(field);738 this.set('Vary', vary.join(', '));739 return this;740 }741742 // set743 this.set('Vary', field);744 return this;revert cookie signature change causing session race conditionsTJ Holowaychukbefore adoption58f2057
lines 745–785why, one step back745};746747/**748 * Render `view` with the given `options` and optional callback `fn`.749 * When a callback function is given a response will _not_ be made750 * automatically, otherwise a response of _200_ and _text/html_ is given.751 *752 * Options:753 *754 * - `cache` boolean hinting to the engine it should cache755 * - `filename` filename of the view being rendered756 *757 * @param {String} view758 * @param {Object|Function} options or callback function759 * @param {Function} fn760 * @api public761 */762763res.render = function(view, options, fn){764 var self = this765 , options = options || {}766 , req = this.req767 , app = req.app;768769 // support callback function as second arg770 if ('function' == typeof options) {771 fn = options, options = {};772 }773774 // merge res.locals775 options._locals = self.locals;776777 // default callback to respond778 fn = fn || function(err, str){779 if (err) return req.next(err);780 self.send(str);781 };782783 // render784 app.render(view, options, fn);785};