Skip to content
Myr

response.js

This file

Path

lib/response.js

1,003 lines · 22.3 KiB · JavaScript

Last changed by

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

History of this file

Take it

The walk stopped after 200 commits: lines older than 8ba3f39 point at it.

Merge tag '4.12.0'Douglas Christopher Wilsonbefore adoptionf6ec710

lines 1–7why, one step back
1/*!
2 * express3 * Copyright(c) 2009-2013 TJ Holowaychuk4 * Copyright(c) 2014-2015 Douglas Christopher Wilson5 * MIT Licensed6 */7

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 8–9why, one step back
8'use strict';
9

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 10–11why, one step back
10/**
11 * Module dependencies.

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 12why, one step back
12 * @private

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 13–14why, one step back
13 */
14

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 15why, one step back
15var Buffer = require('safe-buffer').Buffer

Use content-disposition moduleDouglas Christopher Wilsonbefore adoption6f31218

line 16why, one step back
16var contentDisposition = require('content-disposition');

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

line 17why, one step back
17var encodeUrl = require('encodeurl');

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 18–19why, one step back
18var escapeHtml = require('escape-html');
19var http = require('http');

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 20why, one step back
20var onFinished = require('on-finished');

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

line 21why, one step back
21var path = require('path');

Use path-is-absolute module for absolute path detectionJeremiah Senkpielbefore adoption694869d

line 22why, one step back
22var pathIsAbsolute = require('path-is-absolute');

Merge tag '4.15.0'Douglas Christopher Wilsonbefore adoption501e24e

line 23why, one step back
23var statuses = require('statuses')

Merge tag '3.18.1'Douglas Christopher Wilsonbefore adoptionccc45a7

line 24why, one step back
24var merge = require('utils-merge');

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 25–32why, one step back
25var sign = require('cookie-signature').sign;
26var normalizeType = require('./utils').normalizeType;27var normalizeTypes = require('./utils').normalizeTypes;28var setCharset = require('./utils').setCharset;29var cookie = require('cookie');30var send = require('send');31var extname = path.extname;32var mime = send.mime;

Fix incorrect deprecation warnings on res.downloadDouglas Christopher Wilsonbefore adoption1150ca7

line 33why, one step back
33var resolve = path.resolve;

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 34–37why, one step back
34var vary = require('vary');
3536/**37 * Response prototype.

Merge tag '4.15.0'Douglas Christopher Wilsonbefore adoption501e24e

line 38why, one step back
38 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 39–40why, one step back
39 */
40

Merge tag '4.15.0'Douglas Christopher Wilsonbefore adoption501e24e

line 41why, one step back
41var res = Object.create(http.ServerResponse.prototype)

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 42–43why, one step back
42
43/**

Merge tag '4.15.0'Douglas Christopher Wilsonbefore adoption501e24e

lines 44–50why, one step back
44 * Module exports.
45 * @public46 */4748module.exports = res4950/**

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 51–57why, one step back
51 * Module variables.
52 * @private53 */5455var charsetRegExp = /;\s*charset\s*=/;5657/**

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 58–61why, one step back
58 * Set status `code`.
59 *60 * @param {Number} code61 * @return {ServerResponse}

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 62why, one step back
62 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 63–64why, one step back
63 */
64

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 65why, one step back
65res.status = function status(code) {

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 66–81why, one step back
66 this.statusCode = code;
67 return this;68};6970/**71 * Set Link header field with the given `links`.72 *73 * Examples:74 *75 * res.links({76 * next: 'http://api.example.com/users?page=2',77 * last: 'http://api.example.com/users?page=5'78 * });79 *80 * @param {Object} links81 * @return {ServerResponse}

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 82why, one step back
82 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 83–97why, one step back
83 */
8485res.links = function(links){86 var link = this.get('Link') || '';87 if (link) link += ', ';88 return this.set('Link', link + Object.keys(links).map(function(rel){89 return '<' + links[rel] + '>; rel="' + rel + '"';90 }).join(', '));91};9293/**94 * Send a response.95 *96 * Examples:97 *

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 98why, one step back
98 * res.send(Buffer.from('wahoo'));

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 99–101why, one step back
99 * res.send({ some: 'json' });
100 * res.send('<p>some html</p>');101 *

Deprecate combined status, response signaturesDouglas Christopher Wilsonbefore adoptionfd3b405

line 102why, one step back
102 * @param {string|number|boolean|object|Buffer} body

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 103why, one step back
103 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 104–147why, one step back
104 */
105106res.send = function send(body) {107 var chunk = body;108 var encoding;109 var req = this.req;110 var type;111112 // settings113 var app = this.app;114115 switch (typeof chunk) {116 // string defaulting to html117 case 'string':118 if (!this.get('Content-Type')) {119 this.type('html');120 }121 break;122 case 'boolean':123 case 'number':124 case 'object':125 if (chunk === null) {126 chunk = '';127 } else if (Buffer.isBuffer(chunk)) {128 if (!this.get('Content-Type')) {129 this.type('bin');130 }131 } else {132 return this.json(chunk);133 }134 break;135 }136137 // write strings in utf-8138 if (typeof chunk === 'string') {139 encoding = 'utf8';140 type = this.get('Content-Type');141142 // reflect this in content-type143 if (typeof type === 'string') {144 this.set('Content-Type', setCharset(type, 'utf-8'));145 }146 }147

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

lines 148–151why, one step back
148 // determine if ETag should be generated
149 var etagFn = app.get('etag fn')150 var generateETag = !this.get('ETag') && typeof etagFn === 'function'151

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

line 152why, one step back
152 // populate Content-Length

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 153why, one step back
153 var len

perf: prevent multiple Buffer creation in res.sendDouglas Christopher Wilsonbefore adoptionb43205c

line 154why, one step back
154 if (chunk !== undefined) {

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

lines 155–163why, one step back
155 if (Buffer.isBuffer(chunk)) {
156 // get length of Buffer157 len = chunk.length158 } else if (!generateETag && chunk.length < 1000) {159 // just calculate length when no ETag + small chunk160 len = Buffer.byteLength(chunk, encoding)161 } else {162 // convert chunk to Buffer and calculate163 chunk = Buffer.from(chunk, encoding)

perf: prevent multiple Buffer creation in res.sendDouglas Christopher Wilsonbefore adoptionb43205c

line 164why, one step back
164 encoding = undefined;

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 165why, one step back
165 len = chunk.length

perf: prevent multiple Buffer creation in res.sendDouglas Christopher Wilsonbefore adoptionb43205c

lines 166–167why, one step back
166 }
167

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 168–170why, one step back
168 this.set('Content-Length', len);
169 }170

Merge tag '4.12.0'Douglas Christopher Wilsonbefore adoptionf6ec710

lines 171–172why, one step back
171 // populate ETag
172 var etag;

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

lines 173–174why, one step back
173 if (generateETag && len !== undefined) {
174 if ((etag = etagFn(chunk, encoding))) {

Merge tag '4.12.0'Douglas Christopher Wilsonbefore adoptionf6ec710

line 175why, one step back
175 this.set('ETag', etag);

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 176–182why, one step back
176 }
177 }178179 // freshness180 if (req.fresh) this.statusCode = 304;181182 // strip irrelevant headers

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

line 183why, one step back
183 if (204 === this.statusCode || 304 === this.statusCode) {

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 184–189why, one step back
184 this.removeHeader('Content-Type');
185 this.removeHeader('Content-Length');186 this.removeHeader('Transfer-Encoding');187 chunk = '';188 }189

Merge tag '4.12.0'Douglas Christopher Wilsonbefore adoptionf6ec710

line 190why, one step back
190 if (req.method === 'HEAD') {

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

line 191why, one step back
191 // skip body for HEAD

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

line 192why, one step back
192 this.end();

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

lines 193–195why, one step back
193 } else {
194 // respond195 this.end(chunk, encoding);

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 196–208why, one step back
196 }
197198 return this;199};200201/**202 * Send JSON response.203 *204 * Examples:205 *206 * res.json(null);207 * res.json({ user: 'tj' });208 *

Deprecate combined status, response signaturesDouglas Christopher Wilsonbefore adoptionfd3b405

line 209why, one step back
209 * @param {string|number|boolean|object} obj

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 210why, one step back
210 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 211–215why, one step back
211 */
212213res.json = function json(obj) {214 // settings215 var app = this.app;

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 216why, one step back
216 var escape = app.get('json escape')

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 217–218why, one step back
217 var replacer = app.get('json replacer');
218 var spaces = app.get('json spaces');

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 219why, one step back
219 var body = stringify(obj, replacer, spaces, escape)

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 220–236why, one step back
220
221 // content-type222 if (!this.get('Content-Type')) {223 this.set('Content-Type', 'application/json');224 }225226 return this.send(body);227};228229/**230 * Send JSON response with JSONP callback support.231 *232 * Examples:233 *234 * res.jsonp(null);235 * res.jsonp({ user: 'tj' });236 *

Deprecate combined status, response signaturesDouglas Christopher Wilsonbefore adoptionfd3b405

line 237why, one step back
237 * @param {string|number|boolean|object} obj

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 238why, one step back
238 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 239–243why, one step back
239 */
240241res.jsonp = function jsonp(obj) {242 // settings243 var app = this.app;

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 244why, one step back
244 var escape = app.get('json escape')

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 245–246why, one step back
245 var replacer = app.get('json replacer');
246 var spaces = app.get('json spaces');

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 247why, one step back
247 var body = stringify(obj, replacer, spaces, escape)

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 248–279why, one step back
248 var callback = this.req.query[app.get('jsonp callback name')];
249250 // content-type251 if (!this.get('Content-Type')) {252 this.set('X-Content-Type-Options', 'nosniff');253 this.set('Content-Type', 'application/json');254 }255256 // fixup callback257 if (Array.isArray(callback)) {258 callback = callback[0];259 }260261 // jsonp262 if (typeof callback === 'string' && callback.length !== 0) {263 this.set('X-Content-Type-Options', 'nosniff');264 this.set('Content-Type', 'text/javascript');265266 // restrict callback charset267 callback = callback.replace(/[^\[\]\w$.]/g, '');268269 // replace chars not allowed in JavaScript that are in JSON270 body = body271 .replace(/\u2028/g, '\\u2028')272 .replace(/\u2029/g, '\\u2029');273274 // the /**/ is a specific security mitigation for "Rosetta Flash JSONP abuse"275 // the typeof check is just to reduce client error noise276 body = '/**/ typeof ' + callback + ' === \'function\' && ' + callback + '(' + body + ');';277 }278279 return this.send(body);

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

lines 280–282why, one step back
280};
281282/**

Add res.sendStatusSeth Samuelbefore adoption12f92a5

lines 283–293why, one step back
283 * Send given HTTP status code.
284 *285 * Sets the response status to `statusCode` and the body of the286 * response to the standard description from node's http.STATUS_CODES287 * or the statusCode number if no description.288 *289 * Examples:290 *291 * res.sendStatus(200);292 *293 * @param {number} statusCode

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 294why, one step back
294 * @public

Add res.sendStatusSeth Samuelbefore adoption12f92a5

lines 295–297why, one step back
295 */
296297res.sendStatus = function sendStatus(statusCode) {

Merge tag '4.15.0'Douglas Christopher Wilsonbefore adoption501e24e

line 298why, one step back
298 var body = statuses[statusCode] || String(statusCode)

Add res.sendStatusSeth Samuelbefore adoption12f92a5

lines 299–306why, one step back
299
300 this.statusCode = statusCode;301 this.type('txt');302303 return this.send(body);304};305306/**

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

lines 307–309why, one step back
307 * Transfer the file at the given `path`.
308 *309 * Automatically sets the _Content-Type_ response header field.

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 310why, one step back
310 * The callback `callback(err)` is invoked when the transfer is complete

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

lines 311–343why, one step back
311 * or when an error occurs. Be sure to check `res.sentHeader`
312 * if you wish to attempt responding, as the header and some data313 * may have already been transferred.314 *315 * Options:316 *317 * - `maxAge` defaulting to 0 (can be string converted by `ms`)318 * - `root` root directory for relative filenames319 * - `headers` object of headers to serve with file320 * - `dotfiles` serve dotfiles, defaulting to false; can be `"allow"` to send them321 *322 * Other options are passed along to `send`.323 *324 * Examples:325 *326 * The following example illustrates how `res.sendFile()` may327 * be used as an alternative for the `static()` middleware for328 * dynamic situations. The code backing `res.sendFile()` is actually329 * the same code, so HTTP cache support etc is identical.330 *331 * app.get('/user/:uid/photos/:file', function(req, res){332 * var uid = req.params.uid333 * , file = req.params.file;334 *335 * req.user.mayViewFilesFrom(uid, function(yes){336 * if (yes) {337 * res.sendFile('/uploads/' + uid + '/' + file);338 * } else {339 * res.send(403, 'Sorry! you cant see that.');340 * }341 * });342 * });343 *

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 344why, one step back
344 * @public

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

lines 345–346why, one step back
345 */
346

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 347–348why, one step back
347res.sendFile = function sendFile(path, options, callback) {
348 var done = callback;

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 350why, one step back
350 var res = this;

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

line 351why, one step back
351 var next = req.next;

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 352why, one step back
352 var opts = options || {};

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

lines 353–357why, one step back
353
354 if (!path) {355 throw new TypeError('path argument is required to res.sendFile');356 }357

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

lines 358–361why, one step back
358 if (typeof path !== 'string') {
359 throw new TypeError('path must be a string to res.sendFile')360 }361

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

lines 362–363why, one step back
362 // support function as second arg
363 if (typeof options === 'function') {

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 364–365why, one step back
364 done = options;
365 opts = {};

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

lines 366–367why, one step back
366 }
367

Use path-is-absolute module for absolute path detectionJeremiah Senkpielbefore adoption694869d

line 368why, one step back
368 if (!opts.root && !pathIsAbsolute(path)) {

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

lines 369–371why, one step back
369 throw new TypeError('path must be absolute or specify root to res.sendFile');
370 }371

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 372why, one step back
372 // create file stream

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

line 373why, one step back
373 var pathname = encodeURI(path);

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 374why, one step back
374 var file = send(req, pathname, opts);

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

line 375why, one step back
375

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 376why, one step back
376 // transfer

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 377–378why, one step back
377 sendfile(res, file, opts, function (err) {
378 if (done) return done(err);

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 379why, one step back
379 if (err && err.code === 'EISDIR') return next();

Add res.sendFileDouglas Christopher Wilsonbefore adoption2cb029f

line 380why, one step back
380

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

line 381why, one step back
381 // next() all but write errors

Merge tag '4.12.4'Douglas Christopher Wilsonbefore adoptionf90e045

line 382why, one step back
382 if (err && err.code !== 'ECONNABORTED' && err.syscall !== 'write') {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 383–385why, one step back
383 next(err);
384 }385 });

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 386–391why, one step back
386};
387388/**389 * Transfer the file at the given `path` as an attachment.390 *391 * Optionally providing an alternate attachment `filename`,

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 392why, one step back
392 * and optional callback `callback(err)`. The callback is invoked

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 393–395why, one step back
393 * when the data transfer is complete, or when an error has
394 * ocurred. Be sure to check `res.headersSent` if you plan to respond.395 *

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

lines 396–400why, one step back
396 * Optionally providing an `options` object to use with `res.sendFile()`.
397 * This function will set the `Content-Disposition` header, overriding398 * any `Content-Disposition` header passed as header options in order399 * to set the attachment and filename.400 *

Remove res.sendfileDouglas Christopher Wilsonbefore adoption0fc4f07

line 401why, one step back
401 * This method uses `res.sendFile()`.

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

line 402why, one step back
402 *

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 403why, one step back
403 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 404–405why, one step back
404 */
405

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 406why, one step back
406res.download = function download (path, filename, options, callback) {

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 407–408why, one step back
407 var done = callback;
408 var name = filename;

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 409why, one step back
409 var opts = options || null

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 410why, one step back
410

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 411why, one step back
411 // support function as second or third arg

Fix incorrect deprecation warnings on res.downloadDouglas Christopher Wilsonbefore adoption1150ca7

line 412why, one step back
412 if (typeof filename === 'function') {

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 413–414why, one step back
413 done = filename;
414 name = null;

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

lines 415–418why, one step back
415 opts = null
416 } else if (typeof options === 'function') {417 done = options418 opts = null

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 419–422why, one step back
419 }
420421 // set Content-Disposition when file is sent422 var headers = {

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 423why, one step back
423 'Content-Disposition': contentDisposition(name || path)

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 424–425why, one step back
424 };
425

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

lines 426–440why, one step back
426 // merge user-provided headers
427 if (opts && opts.headers) {428 var keys = Object.keys(opts.headers)429 for (var i = 0; i < keys.length; i++) {430 var key = keys[i]431 if (key.toLowerCase() !== 'content-disposition') {432 headers[key] = opts.headers[key]433 }434 }435 }436437 // merge user-provided options438 opts = Object.create(opts)439 opts.headers = headers440

Fix incorrect deprecation warnings on res.downloadDouglas Christopher Wilsonbefore adoption1150ca7

lines 441–443why, one step back
441 // Resolve the full path for sendFile
442 var fullPath = resolve(path);443

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

lines 444–445why, one step back
444 // send file
445 return this.sendFile(fullPath, opts, done)

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 446–461why, one step back
446};
447448/**449 * Set _Content-Type_ response header with `type` through `mime.lookup()`450 * when it does not contain "/", or set the Content-Type to `type` otherwise.451 *452 * Examples:453 *454 * res.type('.html');455 * res.type('html');456 * res.type('json');457 * res.type('application/json');458 * res.type('png');459 *460 * @param {String} type461 * @return {ServerResponse} for chaining

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 462why, one step back
462 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 463–465why, one step back
463 */
464465res.contentType =

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 466–471why, one step back
466res.type = function contentType(type) {
467 var ct = type.indexOf('/') === -1468 ? mime.lookup(type)469 : type;470471 return this.set('Content-Type', ct);

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 472–527why, one step back
472};
473474/**475 * Respond to the Acceptable formats using an `obj`476 * of mime-type callbacks.477 *478 * This method uses `req.accepted`, an array of479 * acceptable types ordered by their quality values.480 * When "Accept" is not present the _first_ callback481 * is invoked, otherwise the first match is used. When482 * no match is performed the server responds with483 * 406 "Not Acceptable".484 *485 * Content-Type is set for you, however if you choose486 * you may alter this within the callback using `res.type()`487 * or `res.set('Content-Type', ...)`.488 *489 * res.format({490 * 'text/plain': function(){491 * res.send('hey');492 * },493 *494 * 'text/html': function(){495 * res.send('<p>hey</p>');496 * },497 *498 * 'appliation/json': function(){499 * res.send({ message: 'hey' });500 * }501 * });502 *503 * In addition to canonicalized MIME types you may504 * also use extnames mapped to these types:505 *506 * res.format({507 * text: function(){508 * res.send('hey');509 * },510 *511 * html: function(){512 * res.send('<p>hey</p>');513 * },514 *515 * json: function(){516 * res.send({ message: 'hey' });517 * }518 * });519 *520 * By default Express passes an `Error`521 * with a `.status` of 406 to `next(err)`522 * if a match is not made. If you provide523 * a `.default` callback it will be invoked524 * instead.525 *526 * @param {Object} obj527 * @return {ServerResponse} for chaining

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 528why, one step back
528 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 529–538why, one step back
529 */
530531res.format = function(obj){532 var req = this.req;533 var next = req.next;534535 var fn = obj.default;536 if (fn) delete obj.default;537 var keys = Object.keys(obj);538

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 539–541why, one step back
539 var key = keys.length > 0
540 ? req.accepts(keys)541 : false;

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 542–551why, one step back
542
543 this.vary("Accept");544545 if (key) {546 this.set('Content-Type', normalizeType(key).value);547 obj[key](req, this, next);548 } else if (fn) {549 fn();550 } else {551 var err = new Error('Not Acceptable');

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 552why, one step back
552 err.status = err.statusCode = 406;

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 553–564why, one step back
553 err.types = normalizeTypes(keys).map(function(o){ return o.value });
554 next(err);555 }556557 return this;558};559560/**561 * Set _Content-Disposition_ header to _attachment_ with optional `filename`.562 *563 * @param {String} filename564 * @return {ServerResponse}

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 565why, one step back
565 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 566–567why, one step back
566 */
567

Use content-disposition moduleDouglas Christopher Wilsonbefore adoption6f31218

lines 568–572why, one step back
568res.attachment = function attachment(filename) {
569 if (filename) {570 this.type(extname(filename));571 }572

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

line 573why, one step back
573 this.set('Content-Disposition', contentDisposition(filename));

Use content-disposition moduleDouglas Christopher Wilsonbefore adoption6f31218

line 574why, one step back
574

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 575–578why, one step back
575 return this;
576};577578/**

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

lines 579–589why, one step back
579 * Append additional header `field` with value `val`.
580 *581 * Example:582 *583 * res.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);584 * res.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');585 * res.append('Warning', '199 Miscellaneous warning');586 *587 * @param {String} field588 * @param {String|Array} val589 * @return {ServerResponse} for chaining

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 590why, one step back
590 * @public

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

lines 591–607why, one step back
591 */
592593res.append = function append(field, val) {594 var prev = this.get(field);595 var value = val;596597 if (prev) {598 // concat the new and prev vals599 value = Array.isArray(prev) ? prev.concat(val)600 : Array.isArray(val) ? [prev].concat(val)601 : [prev, val];602 }603604 return this.set(field, value);605};606607/**

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 608–618why, one step back
608 * Set header `field` to `val`, or pass
609 * an object of header fields.610 *611 * Examples:612 *613 * res.set('Foo', ['bar', 'baz']);614 * res.set('Accept', 'application/json');615 * res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });616 *617 * Aliased as `res.header()`.618 *

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 619–620why, one step back
619 * @param {String|Object} field
620 * @param {String|Array} val

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

line 621why, one step back
621 * @return {ServerResponse} for chaining

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 622why, one step back
622 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 623–627why, one step back
623 */
624625res.set =626res.header = function header(field, val) {627 if (arguments.length === 2) {

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 628–632why, one step back
628 var value = Array.isArray(val)
629 ? val.map(String)630 : String(val);631632 // add charset to content-type

Merge tag '4.15.4'Douglas Christopher Wilsonbefore adoptionc319fe2

lines 633–640why, one step back
633 if (field.toLowerCase() === 'content-type') {
634 if (Array.isArray(value)) {635 throw new TypeError('Content-Type cannot be set to an Array');636 }637 if (!charsetRegExp.test(value)) {638 var charset = mime.charsets.lookup(value.split(';')[0]);639 if (charset) value += '; charset=' + charset.toLowerCase();640 }

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

line 641why, one step back
641 }

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 642–643why, one step back
642
643 this.setHeader(field, value);

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 644–656why, one step back
644 } else {
645 for (var key in field) {646 this.set(key, field[key]);647 }648 }649 return this;650};651652/**653 * Get value for header `field`.654 *655 * @param {String} field656 * @return {String}

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 657why, one step back
657 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 658–667why, one step back
658 */
659660res.get = function(field){661 return this.getHeader(field);662};663664/**665 * Clear cookie `name`.666 *667 * @param {String} name

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

line 668why, one step back
668 * @param {Object} [options]

build: fix up jsdoc return valuesVasilyev Dmitrybefore adoptionfd86ab8

line 669why, one step back
669 * @return {ServerResponse} for chaining

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 670why, one step back
670 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 671–672why, one step back
671 */
672

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 673–676why, one step back
673res.clearCookie = function clearCookie(name, options) {
674 var opts = merge({ expires: new Date(1), path: '/' }, options);675676 return this.cookie(name, '', opts);

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 677–679why, one step back
677};
678679/**

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 680why, one step back
680 * Set cookie `name` to `value`, with the given `options`.

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 681–692why, one step back
681 *
682 * Options:683 *684 * - `maxAge` max-age in milliseconds, converted to `expires`685 * - `signed` sign the cookie686 * - `path` defaults to "/"687 *688 * Examples:689 *690 * // "Remember Me" for 15 minutes691 * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });692 *

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

line 693why, one step back
693 * // same as above

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 694–696why, one step back
694 * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
695 *696 * @param {String} name

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 697why, one step back
697 * @param {String|Object} value

Merge tag '4.15.4'Douglas Christopher Wilsonbefore adoptionc319fe2

line 698why, one step back
698 * @param {Object} [options]

build: fix up jsdoc return valuesVasilyev Dmitrybefore adoptionfd86ab8

line 699why, one step back
699 * @return {ServerResponse} for chaining

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 700why, one step back
700 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 701–702why, one step back
701 */
702

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 703–704why, one step back
703res.cookie = function (name, value, options) {
704 var opts = merge({}, options);

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

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

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 706–709why, one step back
706 var signed = opts.signed;
707708 if (signed && !secret) {709 throw new Error('cookieParser("secret") required for signed cookies');

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 710–711why, one step back
710 }
711

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 712–717why, one step back
712 var val = typeof value === 'object'
713 ? 'j:' + JSON.stringify(value)714 : String(value);715716 if (signed) {717 val = 's:' + sign(val, secret);

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

line 718why, one step back
718 }

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 719–730why, one step back
719
720 if ('maxAge' in opts) {721 opts.expires = new Date(Date.now() + opts.maxAge);722 opts.maxAge /= 1000;723 }724725 if (opts.path == null) {726 opts.path = '/';727 }728729 this.append('Set-Cookie', cookie.serialize(name, String(val), opts));730

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 731–746why, one step back
731 return this;
732};733734/**735 * Set the location header to `url`.736 *737 * The given `url` can also be "back", which redirects738 * to the _Referrer_ or _Referer_ headers or "/".739 *740 * Examples:741 *742 * res.location('/foo/bar').;743 * res.location('http://example.com');744 * res.location('../login');745 *746 * @param {String} url

build: fix up jsdoc return valuesVasilyev Dmitrybefore adoptionfd86ab8

line 747why, one step back
747 * @return {ServerResponse} for chaining

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 748why, one step back
748 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 749–750why, one step back
749 */
750

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 751–752why, one step back
751res.location = function location(url) {
752 var loc = url;

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 753–754why, one step back
753
754 // "back" is an alias for the referrer

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 755–757why, one step back
755 if (url === 'back') {
756 loc = this.req.get('Referrer') || '/';757 }

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

line 758why, one step back
758

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 759why, one step back
759 // set location

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

line 760why, one step back
760 return this.set('Location', encodeUrl(loc));

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 761–777why, one step back
761};
762763/**764 * Redirect to the given `url` with optional response `status`765 * defaulting to 302.766 *767 * The resulting `url` is determined by `res.location()`, so768 * it will play nicely with mounted apps, relative paths,769 * `"back"` etc.770 *771 * Examples:772 *773 * res.redirect('/foo/bar');774 * res.redirect('http://example.com');775 * res.redirect(301, 'http://example.com');776 * res.redirect('../login'); // /blog/post/1 -> /blog/login777 *

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 778why, one step back
778 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 779–787why, one step back
779 */
780781res.redirect = function redirect(url) {782 var address = url;783 var body;784 var status = 302;785786 // allow status / url787 if (arguments.length === 2) {

Remove res.redirect(url, status) signatureMike Tunnicliffebefore adoption71395f5

lines 788–789why, one step back
788 status = arguments[0]
789 address = arguments[1]

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 790–792why, one step back
790 }
791792 // Set location header

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

line 793why, one step back
793 address = this.location(address).get('Location');

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 794–797why, one step back
794
795 // Support text/{plain,html} by default796 this.format({797 text: function(){

Merge tag '4.15.0'Douglas Christopher Wilsonbefore adoption501e24e

line 798why, one step back
798 body = statuses[status] + '. Redirecting to ' + address

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 799–801why, one step back
799 },
800801 html: function(){

Fix res.redirect body when redirect status specifiedAlex Upadhyaybefore adoption6f0302f

line 802why, one step back
802 var u = escapeHtml(address);

Merge tag '4.15.0'Douglas Christopher Wilsonbefore adoption501e24e

line 803why, one step back
803 body = '<p>' + statuses[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>'

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 804–816why, one step back
804 },
805806 default: function(){807 body = '';808 }809 });810811 // Respond812 this.statusCode = status;813 this.set('Content-Length', Buffer.byteLength(body));814815 if (this.req.method === 'HEAD') {816 this.end();

Merge tag '4.11.2'Douglas Christopher Wilsonbefore adoptiona9ef9e1

lines 817–818why, one step back
817 } else {
818 this.end(body);

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 819–826why, one step back
819 }
820};821822/**823 * Add `field` to Vary. If already present in the Vary set, then824 * this call is simply ignored.825 *826 * @param {Array|String} field

build: fix up jsdoc return valuesVasilyev Dmitrybefore adoptionfd86ab8

line 827why, one step back
827 * @return {ServerResponse} for chaining

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 828why, one step back
828 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 829–846why, one step back
829 */
830831res.vary = function(field){832 vary(this, field);833834 return this;835};836837/**838 * Render `view` with the given `options` and optional callback `fn`.839 * When a callback function is given a response will _not_ be made840 * automatically, otherwise a response of _200_ and _text/html_ is given.841 *842 * Options:843 *844 * - `cache` boolean hinting to the engine it should cache845 * - `filename` filename of the view being rendered846 *

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 847why, one step back
847 * @public

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 848–849why, one step back
848 */
849

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 850–853why, one step back
850res.render = function render(view, options, callback) {
851 var app = this.req.app;852 var done = callback;853 var opts = options || {};

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

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

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 855why, one step back
855 var self = this;

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 856–857why, one step back
856
857 // support callback function as second arg

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 858–860why, one step back
858 if (typeof options === 'function') {
859 done = options;860 opts = {};

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 861–863why, one step back
861 }
862863 // merge res.locals

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 864why, one step back
864 opts._locals = self.locals;

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 865–866why, one step back
865
866 // default callback to respond

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 867why, one step back
867 done = done || function (err, str) {

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

lines 868–872why, one step back
868 if (err) return req.next(err);
869 self.send(str);870 };871872 // render

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

line 873why, one step back
873 app.render(view, opts, done);

4.6.0Douglas Christopher Wilsonbefore adoption8ba3f39

line 874why, one step back
874};

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 875–878why, one step back
875
876// pipe the send file stream877function sendfile(res, file, options, callback) {878 var done = false;

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

line 879why, one step back
879 var streaming;

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 880why, one step back
880

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

lines 881–886why, one step back
881 // request aborted
882 function onaborted() {883 if (done) return;884 done = true;885886 var err = new Error('Request aborted');

Merge tag '4.12.4'Douglas Christopher Wilsonbefore adoptionf90e045

line 887why, one step back
887 err.code = 'ECONNABORTED';

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

lines 888–890why, one step back
888 callback(err);
889 }890

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 891–914why, one step back
891 // directory
892 function ondirectory() {893 if (done) return;894 done = true;895896 var err = new Error('EISDIR, read');897 err.code = 'EISDIR';898 callback(err);899 }900901 // errors902 function onerror(err) {903 if (done) return;904 done = true;905 callback(err);906 }907908 // ended909 function onend() {910 if (done) return;911 done = true;912 callback();913 }914

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

lines 915–919why, one step back
915 // file
916 function onfile() {917 streaming = false;918 }919

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 920–921why, one step back
920 // finished
921 function onfinish(err) {

Merge tag '4.12.4'Douglas Christopher Wilsonbefore adoptionf90e045

line 922why, one step back
922 if (err && err.code === 'ECONNRESET') return onaborted();

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 923–926why, one step back
923 if (err) return onerror(err);
924 if (done) return;925926 setImmediate(function () {

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

lines 927–931why, one step back
927 if (streaming !== false && !done) {
928 onaborted();929 return;930 }931

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 932–933why, one step back
932 if (done) return;
933 done = true;

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

line 934why, one step back
934 callback();

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 935–937why, one step back
935 });
936 }937

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

lines 938–943why, one step back
938 // streaming
939 function onstream() {940 streaming = true;941 }942943 file.on('directory', ondirectory);

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 944–945why, one step back
944 file.on('end', onend);
945 file.on('error', onerror);

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

lines 946–947why, one step back
946 file.on('file', onfile);
947 file.on('stream', onstream);

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 948–964why, one step back
948 onFinished(res, onfinish);
949950 if (options.headers) {951 // set headers on successful transfer952 file.on('headers', function headers(res) {953 var obj = options.headers;954 var keys = Object.keys(obj);955956 for (var i = 0; i < keys.length; i++) {957 var k = keys[i];958 res.setHeader(k, obj[k]);959 }960 });961 }962963 // pipe964 file.pipe(res);

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

lines 965–967why, one step back
965}
966967/**

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

lines 968–975why, one step back
968 * Stringify JSON, like JSON.stringify, but v8 optimized, with the
969 * ability to escape characters that can trigger HTML sniffing.970 *971 * @param {*} value972 * @param {function} replaces973 * @param {number} spaces974 * @param {boolean} escape975 * @returns {string}

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

lines 976–978why, one step back
976 * @private
977 */978

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 979why, one step back
979function stringify (value, replacer, spaces, escape) {

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

lines 980–981why, one step back
980 // v8 checks arguments.length for optimizing simple call
981 // https://bugs.chromium.org/p/v8/issues/detail?id=4730

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

line 982why, one step back
982 var json = replacer || spaces

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

lines 983–984why, one step back
983 ? JSON.stringify(value, replacer, spaces)
984 : JSON.stringify(value);

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

lines 985–994why, one step back
985
986 if (escape) {987 json = json.replace(/[<>&]/g, function (c) {988 switch (c.charCodeAt(0)) {989 case 0x3c:990 return '\\u003c'991 case 0x3e:992 return '\\u003e'993 case 0x26:994 return '\\u0026'

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

line 995why, one step back
995 /* istanbul ignore next: unreachable default */

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

lines 996–1002why, one step back
996 default:
997 return c998 }999 })1000 }10011002 return json

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 1003why, one step back
1003}