response.js
This file
Path
lib/response.js
802 lines · 18.1 KiB · JavaScript
Last changed by
some jshint cleanupJonathan Ongbefore adoption5572897
History of this fileTake it
The walk stopped after 200 commits: lines older than 579857c point at it.
fix example portTJ Holowaychukbefore adoption579857c
lines 1–6why, one step back1/**2 * Module dependencies.3 */45var http = require('http')6 , path = require('path')use utils-merge module to mixin object propertiesRoman Shtylmanbefore adoption718e68f
line 7why, one step back7 , mixin = require('utils-merge')use escape-html module to escape htmlRoman Shtylmanbefore adoption63c6a9c
line 8why, one step back8 , escapeHtml = require('escape-html')fix example portTJ Holowaychukbefore adoption579857c
lines 9–16why, one step back9 , sign = require('cookie-signature').sign10 , normalizeType = require('./utils').normalizeType11 , normalizeTypes = require('./utils').normalizeTypes12 , etag = require('./utils').etag13 , statusCodes = http.STATUS_CODES14 , cookie = require('cookie')15 , send = require('send')16 , basename = path.basenameremove last pieces of connect dependencyRoman Shtylmanbefore adoption1396e08
line 17why, one step back17 , extname = path.extnamemove the patch to the response protoJonathan Ongbefore adoption3112f92
lines 18–20why, one step back18 , mime = send.mime;19var ServerResponse = http.ServerResponse;20var setHeader = ServerResponse.prototype.setHeader;fix example portTJ Holowaychukbefore adoption579857c
lines 21–58why, one step back2122/**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 back59 var link = this.get('Link') || '';60 if (link) link += ', ';61 return this.set('Link', link + Object.keys(links).map(function(rel){fix example portTJ Holowaychukbefore adoption579857c
lines 62–83why, one step back62 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 back84 var req = this.req;85 var head = 'HEAD' == req.method;86 var len;fix example portTJ Holowaychukbefore adoption579857c
line 87why, one step back87Merge pull request #1694 from kavu/add_disable_etagTJ Holowaychukbefore adoption610e172
lines 88–90why, one step back88 // settings89 var app = this.app;90fix example portTJ Holowaychukbefore adoption579857c
lines 91–136why, one step back91 // allow status / body92 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/ supportalways send ETag when content-length > 0Jonathan Ongbefore adoption55d1a4f
line 137why, one step back137 if (app.settings.etag && len && 'GET' == req.method) {fix example portTJ Holowaychukbefore adoption579857c
lines 138–193why, one step back138 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-typeRevert "remove charset from json responses. Closes #1631"TJ Holowaychukbefore adoption6cf6c8b
line 194why, one step back194 this.charset = this.charset || 'utf-8';fix example portTJ Holowaychukbefore adoption579857c
lines 195–242why, one step back195 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 back243 if (Array.isArray(callback)) callback = callback[0];fix example portTJ Holowaychukbefore adoption579857c
lines 244–245why, one step back244 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 back246 body = 'typeof ' + cb + ' === \'function\' && ' + cb + '(' + body + ');';fix example portTJ Holowaychukbefore adoption579857c
lines 247–314why, one step back247 }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();remove ServerResonse.headerSent monkey patchRoman Shtylmanbefore adoption6835289
line 315why, one step back315 if (!self.headersSent) self.removeHeader('Content-Disposition');fix example portTJ Holowaychukbefore adoption579857c
lines 316–320why, one step back316317 // callback available318 if (fn) return fn(err);319320 // list in limbo if there's no callbackremove ServerResonse.headerSent monkey patchRoman Shtylmanbefore adoption6835289
line 321why, one step back321 if (self.headersSent) return;fix example portTJ Holowaychukbefore adoption579857c
lines 322–327why, one step back322323 // delegate324 next(err);325 }326327 // streamingMerge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption0b88208
line 328why, one step back328 function stream(stream) {fix example portTJ Holowaychukbefore adoption579857c
lines 329–330why, one step back329 if (done) return;330 cleanup();Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption0b88208
line 331why, one step back331 if (fn) stream.on('end', fn);fix example portTJ Holowaychukbefore adoption579857c
lines 332–355why, one step back332 }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 hasremove ServerResonse.headerSent monkey patchRoman Shtylmanbefore adoption6835289
line 356why, one step back356 * ocurred. Be sure to check `res.headersSent` if you plan to respond.fix example portTJ Holowaychukbefore adoption579857c
lines 357–468why, one step back357 *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);468add res.vary(). Closes #1682cjihrigbefore adoptione5de08f
line 469why, one step back469 this.vary("Accept");fix example portTJ Holowaychukbefore adoption579857c
lines 470–471why, one step back470471 if (key) {Merge pull request #1747 from sorribas/masterTJ Holowaychukbefore adoption1c87e5e
lines 472–473why, one step back472 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 back474 if (charset) type += '; charset=' + charset;Merge pull request #1747 from sorribas/masterTJ Holowaychukbefore adoption1c87e5e
line 475why, one step back475 this.set('Content-Type', type);fix example portTJ Holowaychukbefore adoption579857c
lines 476–560why, one step back476 obj[key](req, this, next);477 } else if (fn) {478 fn();479 } else {480 var err = new Error('Not Acceptable');481 err.status = 406;482 err.types = normalizeTypes(keys).map(function(o){ return o.value });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, '', optionsuse utils-merge module to mixin object propertiesRoman Shtylmanbefore adoption718e68f
line 561why, one step back561 ? mixin(opts, options)fix example portTJ Holowaychukbefore adoption579857c
lines 562–588why, one step back562 : 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 back589 options = mixin({}, options);fix example portTJ Holowaychukbefore adoption579857c
lines 590–591why, one step back590 var secret = this.req.secret;591 var signed = options.signed;remove last pieces of connect dependencyRoman Shtylmanbefore adoption1396e08
line 592why, one step back592 if (signed && !secret) throw new Error('cookieParser("secret") required for signed cookies');Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoptionea2664a
line 593why, one step back593 if ('number' == typeof val) val = val.toString();fix example portTJ Holowaychukbefore adoption579857c
lines 594–600why, one step back594 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 = '/';move support for multiple `res.cookie` calls to lib/responseRoman Shtylmanbefore adoptiond42d8f5
lines 601–612why, one step back601 var headerVal = cookie.serialize(name, String(val), options);602603 // supports multiple 'res.cookie' calls by getting previous value604 var prev = this.get('Set-Cookie');605 if (prev) {606 if (Array.isArray(prev)) {607 headerVal = prev.concat(headerVal);608 } else {609 headerVal = [prev, headerVal];610 }611 }612 this.set('Set-Cookie', headerVal);fix example portTJ Holowaychukbefore adoption579857c
lines 613–619why, one step back613 return this;614};615616617/**618 * Set the location header to `url`.619 *Merge pull request #1829 from michaelficarra/patch-1TJ Holowaychukbefore adoptionde54af4
line 620why, one step back620 * The given `url` can also be "back", which redirectsfix example portTJ Holowaychukbefore adoption579857c
lines 621–626why, one step back621 * to the _Referrer_ or _Referer_ headers or "/".622 *623 * Examples:624 *625 * res.location('/foo/bar').;626 * res.location('http://example.com');res.location: remove resolving relative urlsJonathan Ongbefore adoptionaac1d52
line 627why, one step back627 * res.location('../login');fix example portTJ Holowaychukbefore adoption579857c
lines 628–633why, one step back628 *629 * @param {String} url630 * @api public631 */632633res.location = function(url){res.location: remove resolving relative urlsJonathan Ongbefore adoptionaac1d52
line 634why, one step back634 var req = this.req;fix example portTJ Holowaychukbefore adoption579857c
line 635why, one step back635Merge pull request #1829 from michaelficarra/patch-1TJ Holowaychukbefore adoptionde54af4
line 636why, one step back636 // "back" is an alias for the referrerocdTJ Holowaychukbefore adoption8a7a695
line 637why, one step back637 if ('back' == url) url = req.get('Referrer') || '/';fix example portTJ Holowaychukbefore adoption579857c
lines 638–665why, one step back638639 // Respond640 this.set('Location', url);641 return this;642};643644/**645 * Redirect to the given `url` with optional response `status`646 * defaulting to 302.647 *648 * The resulting `url` is determined by `res.location()`, so649 * it will play nicely with mounted apps, relative paths,650 * `"back"` etc.651 *652 * Examples:653 *654 * res.redirect('/foo/bar');655 * res.redirect('http://example.com');656 * res.redirect(301, 'http://example.com');657 * res.redirect('http://example.com', 301);658 * res.redirect('../login'); // /blog/post/1 -> /blog/login659 *660 * @param {String} url661 * @param {Number} code662 * @api public663 */664665res.redirect = function(url){lint: remove unused stuffJonathan Ongbefore adoption9bed2b8
line 666why, one step back666 var head = 'HEAD' == this.req.methodfix example portTJ Holowaychukbefore adoption579857c
lines 667–690why, one step back667 , status = 302668 , body;669670 // allow status / url671 if (2 == arguments.length) {672 if ('number' == typeof url) {673 status = url;674 url = arguments[1];675 } else {676 status = arguments[1];677 }678 }679680 // Set location header681 this.location(url);682 url = this.get('Location');683684 // Support text/{plain,html} by default685 this.format({686 text: function(){687 body = statusCodes[status] + '. Redirecting to ' + encodeURI(url);688 },689690 html: function(){use escape-html module to escape htmlRoman Shtylmanbefore adoption63c6a9c
line 691why, one step back691 var u = escapeHtml(url);fix example portTJ Holowaychukbefore adoption579857c
lines 692–703why, one step back692 body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>';693 },694695 default: function(){696 body = '';697 }698 });699700 // Respond701 this.statusCode = status;702 this.set('Content-Length', Buffer.byteLength(body));703 this.end(head ? null : body);add res.vary(). Closes #1682cjihrigbefore adoptione5de08f
lines 704–730why, one step back704};705706/**707 * Add `field` to Vary. If already present in the Vary set, then708 * this call is simply ignored.709 *710 * @param {Array|String} field711 * @param {ServerResponse} for chaining712 * @api public713 */714715res.vary = function(field){716 var self = this;717718 // nothing719 if (!field) return this;720721 // array722 if (Array.isArray(field)) {723 field.forEach(function(field){724 self.vary(field);725 });726 return;727 }728729 var vary = this.get('Vary');730Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoptionbd8b9f5
line 731why, one step back731 // appendadd res.vary(). Closes #1682cjihrigbefore adoptione5de08f
lines 732–741why, one step back732 if (vary) {733 vary = vary.split(/ *, */);734 if (!~vary.indexOf(field)) vary.push(field);735 this.set('Vary', vary.join(', '));736 return this;737 }738739 // set740 this.set('Vary', field);741 return this;fix example portTJ Holowaychukbefore adoption579857c
lines 742–781why, one step back742};743744/**745 * Render `view` with the given `options` and optional callback `fn`.746 * When a callback function is given a response will _not_ be made747 * automatically, otherwise a response of _200_ and _text/html_ is given.748 *749 * Options:750 *751 * - `cache` boolean hinting to the engine it should cache752 * - `filename` filename of the view being rendered753 *754 * @param {String} view755 * @param {Object|Function} options or callback function756 * @param {Function} fn757 * @api public758 */759760res.render = function(view, options, fn){761 var self = this762 , options = options || {}763 , req = this.req764 , app = req.app;765766 // support callback function as second arg767 if ('function' == typeof options) {768 fn = options, options = {};769 }770771 // merge res.locals772 options._locals = self.locals;773774 // default callback to respond775 fn = fn || function(err, str){776 if (err) return req.next(err);777 self.send(str);778 };779780 // render781 app.render(view, options, fn);move the patch to the response protoJonathan Ongbefore adoption3112f92
lines 782–801why, one step back782};783784785/**786 * Set header `field` to `val`, special-casing787 * the `Set-Cookie` field for multiple support.788 *789 * @param {String} field790 * @param {String} val791 * @api public792 */793794res.setHeader = function(field, val){795 var key = field.toLowerCase();796797 if ('content-type' == key && this.charset) {798 val += '; charset=' + this.charset;799 }800801 return setHeader.call(this, field, val);fix example portTJ Holowaychukbefore adoption579857c
line 802why, one step back802};