format: prettify entire project
This commit is contained in:
87
node_modules/express/lib/application.js
generated
vendored
87
node_modules/express/lib/application.js
generated
vendored
@ -28,21 +28,21 @@ var deprecate = require('depd')('express');
|
||||
var flatten = require('array-flatten');
|
||||
var merge = require('utils-merge');
|
||||
var resolve = require('path').resolve;
|
||||
var setPrototypeOf = require('setprototypeof')
|
||||
var setPrototypeOf = require('setprototypeof');
|
||||
|
||||
/**
|
||||
* Module variables.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
var slice = Array.prototype.slice;
|
||||
|
||||
/**
|
||||
* Application prototype.
|
||||
*/
|
||||
|
||||
var app = exports = module.exports = {};
|
||||
var app = (exports = module.exports = {});
|
||||
|
||||
/**
|
||||
* Variable for trust proxy inheritance back-compat
|
||||
@ -88,24 +88,26 @@ app.defaultConfiguration = function defaultConfiguration() {
|
||||
// trust proxy inherit back-compat
|
||||
Object.defineProperty(this.settings, trustProxyDefaultSymbol, {
|
||||
configurable: true,
|
||||
value: true
|
||||
value: true,
|
||||
});
|
||||
|
||||
debug('booting in %s mode', env);
|
||||
|
||||
this.on('mount', function onmount(parent) {
|
||||
// inherit trust proxy
|
||||
if (this.settings[trustProxyDefaultSymbol] === true
|
||||
&& typeof parent.settings['trust proxy fn'] === 'function') {
|
||||
if (
|
||||
this.settings[trustProxyDefaultSymbol] === true &&
|
||||
typeof parent.settings['trust proxy fn'] === 'function'
|
||||
) {
|
||||
delete this.settings['trust proxy'];
|
||||
delete this.settings['trust proxy fn'];
|
||||
}
|
||||
|
||||
// inherit protos
|
||||
setPrototypeOf(this.request, parent.request)
|
||||
setPrototypeOf(this.response, parent.response)
|
||||
setPrototypeOf(this.engines, parent.engines)
|
||||
setPrototypeOf(this.settings, parent.settings)
|
||||
setPrototypeOf(this.request, parent.request);
|
||||
setPrototypeOf(this.response, parent.response);
|
||||
setPrototypeOf(this.engines, parent.engines);
|
||||
setPrototypeOf(this.settings, parent.settings);
|
||||
});
|
||||
|
||||
// setup locals
|
||||
@ -127,9 +129,11 @@ app.defaultConfiguration = function defaultConfiguration() {
|
||||
}
|
||||
|
||||
Object.defineProperty(this, 'router', {
|
||||
get: function() {
|
||||
throw new Error('\'app.router\' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.');
|
||||
}
|
||||
get: function () {
|
||||
throw new Error(
|
||||
"'app.router' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app."
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@ -145,7 +149,7 @@ app.lazyrouter = function lazyrouter() {
|
||||
if (!this._router) {
|
||||
this._router = new Router({
|
||||
caseSensitive: this.enabled('case sensitive routing'),
|
||||
strict: this.enabled('strict routing')
|
||||
strict: this.enabled('strict routing'),
|
||||
});
|
||||
|
||||
this._router.use(query(this.get('query parser fn')));
|
||||
@ -166,10 +170,12 @@ app.handle = function handle(req, res, callback) {
|
||||
var router = this._router;
|
||||
|
||||
// final handler
|
||||
var done = callback || finalhandler(req, res, {
|
||||
env: this.get('env'),
|
||||
onerror: logerror.bind(this)
|
||||
});
|
||||
var done =
|
||||
callback ||
|
||||
finalhandler(req, res, {
|
||||
env: this.get('env'),
|
||||
onerror: logerror.bind(this),
|
||||
});
|
||||
|
||||
// no routes
|
||||
if (!router) {
|
||||
@ -214,7 +220,7 @@ app.use = function use(fn) {
|
||||
var fns = flatten(slice.call(arguments, offset));
|
||||
|
||||
if (fns.length === 0) {
|
||||
throw new TypeError('app.use() requires a middleware function')
|
||||
throw new TypeError('app.use() requires a middleware function');
|
||||
}
|
||||
|
||||
// setup router
|
||||
@ -235,8 +241,8 @@ app.use = function use(fn) {
|
||||
router.use(path, function mounted_app(req, res, next) {
|
||||
var orig = req.app;
|
||||
fn.handle(req, res, function (err) {
|
||||
setPrototypeOf(req, orig.request)
|
||||
setPrototypeOf(res, orig.response)
|
||||
setPrototypeOf(req, orig.request);
|
||||
setPrototypeOf(res, orig.response);
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
@ -303,9 +309,7 @@ app.engine = function engine(ext, fn) {
|
||||
}
|
||||
|
||||
// get file extension
|
||||
var extension = ext[0] !== '.'
|
||||
? '.' + ext
|
||||
: ext;
|
||||
var extension = ext[0] !== '.' ? '.' + ext : ext;
|
||||
|
||||
// store engine
|
||||
this.engines[extension] = fn;
|
||||
@ -359,17 +363,17 @@ app.param = function param(name, fn) {
|
||||
app.set = function set(setting, val) {
|
||||
if (arguments.length === 1) {
|
||||
// app.get(setting)
|
||||
var settings = this.settings
|
||||
var settings = this.settings;
|
||||
|
||||
while (settings && settings !== Object.prototype) {
|
||||
if (hasOwnProperty.call(settings, setting)) {
|
||||
return settings[setting]
|
||||
return settings[setting];
|
||||
}
|
||||
|
||||
settings = Object.getPrototypeOf(settings)
|
||||
settings = Object.getPrototypeOf(settings);
|
||||
}
|
||||
|
||||
return undefined
|
||||
return undefined;
|
||||
}
|
||||
|
||||
debug('set "%s" to %o', setting, val);
|
||||
@ -391,7 +395,7 @@ app.set = function set(setting, val) {
|
||||
// trust proxy inherit back-compat
|
||||
Object.defineProperty(this.settings, trustProxyDefaultSymbol, {
|
||||
configurable: true,
|
||||
value: false
|
||||
value: false,
|
||||
});
|
||||
|
||||
break;
|
||||
@ -415,9 +419,7 @@ app.set = function set(setting, val) {
|
||||
*/
|
||||
|
||||
app.path = function path() {
|
||||
return this.parent
|
||||
? this.parent.path() + this.mountpath
|
||||
: '';
|
||||
return this.parent ? this.parent.path() + this.mountpath : '';
|
||||
};
|
||||
|
||||
/**
|
||||
@ -486,8 +488,8 @@ app.disable = function disable(setting) {
|
||||
* Delegate `.VERB(...)` calls to `router.VERB(...)`.
|
||||
*/
|
||||
|
||||
methods.forEach(function(method){
|
||||
app[method] = function(path){
|
||||
methods.forEach(function (method) {
|
||||
app[method] = function (path) {
|
||||
if (method === 'get' && arguments.length === 1) {
|
||||
// app.get(setting)
|
||||
return this.set(path);
|
||||
@ -587,14 +589,21 @@ app.render = function render(name, options, callback) {
|
||||
view = new View(name, {
|
||||
defaultEngine: this.get('view engine'),
|
||||
root: this.get('views'),
|
||||
engines: engines
|
||||
engines: engines,
|
||||
});
|
||||
|
||||
if (!view.path) {
|
||||
var dirs = Array.isArray(view.root) && view.root.length > 1
|
||||
? 'directories "' + view.root.slice(0, -1).join('", "') + '" or "' + view.root[view.root.length - 1] + '"'
|
||||
: 'directory "' + view.root + '"'
|
||||
var err = new Error('Failed to lookup view "' + name + '" in views ' + dirs);
|
||||
var dirs =
|
||||
Array.isArray(view.root) && view.root.length > 1 ?
|
||||
'directories "' +
|
||||
view.root.slice(0, -1).join('", "') +
|
||||
'" or "' +
|
||||
view.root[view.root.length - 1] +
|
||||
'"'
|
||||
: 'directory "' + view.root + '"';
|
||||
var err = new Error(
|
||||
'Failed to lookup view "' + name + '" in views ' + dirs
|
||||
);
|
||||
err.view = view;
|
||||
return done(err);
|
||||
}
|
||||
|
32
node_modules/express/lib/express.js
generated
vendored
32
node_modules/express/lib/express.js
generated
vendored
@ -12,7 +12,7 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var bodyParser = require('body-parser')
|
||||
var bodyParser = require('body-parser');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var mixin = require('merge-descriptors');
|
||||
var proto = require('./application');
|
||||
@ -35,7 +35,7 @@ exports = module.exports = createApplication;
|
||||
*/
|
||||
|
||||
function createApplication() {
|
||||
var app = function(req, res, next) {
|
||||
var app = function (req, res, next) {
|
||||
app.handle(req, res, next);
|
||||
};
|
||||
|
||||
@ -44,13 +44,13 @@ function createApplication() {
|
||||
|
||||
// expose the prototype that will get set on requests
|
||||
app.request = Object.create(req, {
|
||||
app: { configurable: true, enumerable: true, writable: true, value: app }
|
||||
})
|
||||
app: { configurable: true, enumerable: true, writable: true, value: app },
|
||||
});
|
||||
|
||||
// expose the prototype that will get set on responses
|
||||
app.response = Object.create(res, {
|
||||
app: { configurable: true, enumerable: true, writable: true, value: app }
|
||||
})
|
||||
app: { configurable: true, enumerable: true, writable: true, value: app },
|
||||
});
|
||||
|
||||
app.init();
|
||||
return app;
|
||||
@ -75,12 +75,12 @@ exports.Router = Router;
|
||||
* Expose middleware
|
||||
*/
|
||||
|
||||
exports.json = bodyParser.json
|
||||
exports.json = bodyParser.json;
|
||||
exports.query = require('./middleware/query');
|
||||
exports.raw = bodyParser.raw
|
||||
exports.raw = bodyParser.raw;
|
||||
exports.static = require('serve-static');
|
||||
exports.text = bodyParser.text
|
||||
exports.urlencoded = bodyParser.urlencoded
|
||||
exports.text = bodyParser.text;
|
||||
exports.urlencoded = bodyParser.urlencoded;
|
||||
|
||||
/**
|
||||
* Replace removed middleware with an appropriate error message.
|
||||
@ -103,14 +103,18 @@ var removedMiddlewares = [
|
||||
'directory',
|
||||
'limit',
|
||||
'multipart',
|
||||
'staticCache'
|
||||
]
|
||||
'staticCache',
|
||||
];
|
||||
|
||||
removedMiddlewares.forEach(function (name) {
|
||||
Object.defineProperty(exports, name, {
|
||||
get: function () {
|
||||
throw new Error('Most middleware (like ' + name + ') is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.');
|
||||
throw new Error(
|
||||
'Most middleware (like ' +
|
||||
name +
|
||||
') is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.'
|
||||
);
|
||||
},
|
||||
configurable: true
|
||||
configurable: true,
|
||||
});
|
||||
});
|
||||
|
11
node_modules/express/lib/middleware/init.js
generated
vendored
11
node_modules/express/lib/middleware/init.js
generated
vendored
@ -13,7 +13,7 @@
|
||||
* @private
|
||||
*/
|
||||
|
||||
var setPrototypeOf = require('setprototypeof')
|
||||
var setPrototypeOf = require('setprototypeof');
|
||||
|
||||
/**
|
||||
* Initialization middleware, exposing the
|
||||
@ -25,19 +25,18 @@ var setPrototypeOf = require('setprototypeof')
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.init = function(app){
|
||||
return function expressInit(req, res, next){
|
||||
exports.init = function (app) {
|
||||
return function expressInit(req, res, next) {
|
||||
if (app.enabled('x-powered-by')) res.setHeader('X-Powered-By', 'Express');
|
||||
req.res = res;
|
||||
res.req = req;
|
||||
req.next = next;
|
||||
|
||||
setPrototypeOf(req, app.request)
|
||||
setPrototypeOf(res, app.response)
|
||||
setPrototypeOf(req, app.request);
|
||||
setPrototypeOf(res, app.response);
|
||||
|
||||
res.locals = res.locals || Object.create(null);
|
||||
|
||||
next();
|
||||
};
|
||||
};
|
||||
|
||||
|
6
node_modules/express/lib/middleware/query.js
generated
vendored
6
node_modules/express/lib/middleware/query.js
generated
vendored
@ -12,7 +12,7 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var merge = require('utils-merge')
|
||||
var merge = require('utils-merge');
|
||||
var parseUrl = require('parseurl');
|
||||
var qs = require('qs');
|
||||
|
||||
@ -23,7 +23,7 @@ var qs = require('qs');
|
||||
*/
|
||||
|
||||
module.exports = function query(options) {
|
||||
var opts = merge({}, options)
|
||||
var opts = merge({}, options);
|
||||
var queryparse = qs.parse;
|
||||
|
||||
if (typeof options === 'function') {
|
||||
@ -36,7 +36,7 @@ module.exports = function query(options) {
|
||||
opts.allowPrototypes = true;
|
||||
}
|
||||
|
||||
return function query(req, res, next){
|
||||
return function query(req, res, next) {
|
||||
if (!req.query) {
|
||||
var val = parseUrl(req).query;
|
||||
req.query = queryparse(val, opts);
|
||||
|
110
node_modules/express/lib/request.js
generated
vendored
110
node_modules/express/lib/request.js
generated
vendored
@ -28,14 +28,14 @@ var proxyaddr = require('proxy-addr');
|
||||
* @public
|
||||
*/
|
||||
|
||||
var req = Object.create(http.IncomingMessage.prototype)
|
||||
var req = Object.create(http.IncomingMessage.prototype);
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
* @public
|
||||
*/
|
||||
|
||||
module.exports = req
|
||||
module.exports = req;
|
||||
|
||||
/**
|
||||
* Return request header.
|
||||
@ -61,8 +61,7 @@ module.exports = req
|
||||
* @public
|
||||
*/
|
||||
|
||||
req.get =
|
||||
req.header = function header(name) {
|
||||
req.get = req.header = function header(name) {
|
||||
if (!name) {
|
||||
throw new TypeError('name argument is required to req.get');
|
||||
}
|
||||
@ -76,8 +75,7 @@ req.header = function header(name) {
|
||||
switch (lc) {
|
||||
case 'referer':
|
||||
case 'referrer':
|
||||
return this.headers.referrer
|
||||
|| this.headers.referer;
|
||||
return this.headers.referrer || this.headers.referer;
|
||||
default:
|
||||
return this.headers[lc];
|
||||
}
|
||||
@ -129,7 +127,7 @@ req.header = function header(name) {
|
||||
* @public
|
||||
*/
|
||||
|
||||
req.accepts = function(){
|
||||
req.accepts = function () {
|
||||
var accept = accepts(this);
|
||||
return accept.types.apply(accept, arguments);
|
||||
};
|
||||
@ -142,13 +140,15 @@ req.accepts = function(){
|
||||
* @public
|
||||
*/
|
||||
|
||||
req.acceptsEncodings = function(){
|
||||
req.acceptsEncodings = function () {
|
||||
var accept = accepts(this);
|
||||
return accept.encodings.apply(accept, arguments);
|
||||
};
|
||||
|
||||
req.acceptsEncoding = deprecate.function(req.acceptsEncodings,
|
||||
'req.acceptsEncoding: Use acceptsEncodings instead');
|
||||
req.acceptsEncoding = deprecate.function(
|
||||
req.acceptsEncodings,
|
||||
'req.acceptsEncoding: Use acceptsEncodings instead'
|
||||
);
|
||||
|
||||
/**
|
||||
* Check if the given `charset`s are acceptable,
|
||||
@ -159,13 +159,15 @@ req.acceptsEncoding = deprecate.function(req.acceptsEncodings,
|
||||
* @public
|
||||
*/
|
||||
|
||||
req.acceptsCharsets = function(){
|
||||
req.acceptsCharsets = function () {
|
||||
var accept = accepts(this);
|
||||
return accept.charsets.apply(accept, arguments);
|
||||
};
|
||||
|
||||
req.acceptsCharset = deprecate.function(req.acceptsCharsets,
|
||||
'req.acceptsCharset: Use acceptsCharsets instead');
|
||||
req.acceptsCharset = deprecate.function(
|
||||
req.acceptsCharsets,
|
||||
'req.acceptsCharset: Use acceptsCharsets instead'
|
||||
);
|
||||
|
||||
/**
|
||||
* Check if the given `lang`s are acceptable,
|
||||
@ -176,13 +178,15 @@ req.acceptsCharset = deprecate.function(req.acceptsCharsets,
|
||||
* @public
|
||||
*/
|
||||
|
||||
req.acceptsLanguages = function(){
|
||||
req.acceptsLanguages = function () {
|
||||
var accept = accepts(this);
|
||||
return accept.languages.apply(accept, arguments);
|
||||
};
|
||||
|
||||
req.acceptsLanguage = deprecate.function(req.acceptsLanguages,
|
||||
'req.acceptsLanguage: Use acceptsLanguages instead');
|
||||
req.acceptsLanguage = deprecate.function(
|
||||
req.acceptsLanguages,
|
||||
'req.acceptsLanguage: Use acceptsLanguages instead'
|
||||
);
|
||||
|
||||
/**
|
||||
* Parse Range header field, capping to the given `size`.
|
||||
@ -237,10 +241,10 @@ req.param = function param(name, defaultValue) {
|
||||
var body = this.body || {};
|
||||
var query = this.query || {};
|
||||
|
||||
var args = arguments.length === 1
|
||||
? 'name'
|
||||
: 'name, default';
|
||||
deprecate('req.param(' + args + '): Use req.params, req.body, or req.query instead');
|
||||
var args = arguments.length === 1 ? 'name' : 'name, default';
|
||||
deprecate(
|
||||
'req.param(' + args + '): Use req.params, req.body, or req.query instead'
|
||||
);
|
||||
|
||||
if (null != params[name] && params.hasOwnProperty(name)) return params[name];
|
||||
if (null != body[name]) return body[name];
|
||||
@ -303,10 +307,8 @@ req.is = function is(types) {
|
||||
* @public
|
||||
*/
|
||||
|
||||
defineGetter(req, 'protocol', function protocol(){
|
||||
var proto = this.connection.encrypted
|
||||
? 'https'
|
||||
: 'http';
|
||||
defineGetter(req, 'protocol', function protocol() {
|
||||
var proto = this.connection.encrypted ? 'https' : 'http';
|
||||
var trust = this.app.get('trust proxy fn');
|
||||
|
||||
if (!trust(this.connection.remoteAddress, 0)) {
|
||||
@ -315,12 +317,10 @@ defineGetter(req, 'protocol', function protocol(){
|
||||
|
||||
// Note: X-Forwarded-Proto is normally only ever a
|
||||
// single value, but this is to be safe.
|
||||
var header = this.get('X-Forwarded-Proto') || proto
|
||||
var index = header.indexOf(',')
|
||||
var header = this.get('X-Forwarded-Proto') || proto;
|
||||
var index = header.indexOf(',');
|
||||
|
||||
return index !== -1
|
||||
? header.substring(0, index).trim()
|
||||
: header.trim()
|
||||
return index !== -1 ? header.substring(0, index).trim() : header.trim();
|
||||
});
|
||||
|
||||
/**
|
||||
@ -332,7 +332,7 @@ defineGetter(req, 'protocol', function protocol(){
|
||||
* @public
|
||||
*/
|
||||
|
||||
defineGetter(req, 'secure', function secure(){
|
||||
defineGetter(req, 'secure', function secure() {
|
||||
return this.protocol === 'https';
|
||||
});
|
||||
|
||||
@ -346,7 +346,7 @@ defineGetter(req, 'secure', function secure(){
|
||||
* @public
|
||||
*/
|
||||
|
||||
defineGetter(req, 'ip', function ip(){
|
||||
defineGetter(req, 'ip', function ip() {
|
||||
var trust = this.app.get('trust proxy fn');
|
||||
return proxyaddr(this, trust);
|
||||
});
|
||||
@ -369,9 +369,9 @@ defineGetter(req, 'ips', function ips() {
|
||||
|
||||
// reverse the order (to farthest -> closest)
|
||||
// and remove socket address
|
||||
addrs.reverse().pop()
|
||||
addrs.reverse().pop();
|
||||
|
||||
return addrs
|
||||
return addrs;
|
||||
});
|
||||
|
||||
/**
|
||||
@ -395,9 +395,7 @@ defineGetter(req, 'subdomains', function subdomains() {
|
||||
if (!hostname) return [];
|
||||
|
||||
var offset = this.app.get('subdomain offset');
|
||||
var subdomains = !isIP(hostname)
|
||||
? hostname.split('.').reverse()
|
||||
: [hostname];
|
||||
var subdomains = !isIP(hostname) ? hostname.split('.').reverse() : [hostname];
|
||||
|
||||
return subdomains.slice(offset);
|
||||
});
|
||||
@ -424,7 +422,7 @@ defineGetter(req, 'path', function path() {
|
||||
* @public
|
||||
*/
|
||||
|
||||
defineGetter(req, 'hostname', function hostname(){
|
||||
defineGetter(req, 'hostname', function hostname() {
|
||||
var trust = this.app.get('trust proxy fn');
|
||||
var host = this.get('X-Forwarded-Host');
|
||||
|
||||
@ -433,27 +431,27 @@ defineGetter(req, 'hostname', function hostname(){
|
||||
} else if (host.indexOf(',') !== -1) {
|
||||
// Note: X-Forwarded-Host is normally only ever a
|
||||
// single value, but this is to be safe.
|
||||
host = host.substring(0, host.indexOf(',')).trimRight()
|
||||
host = host.substring(0, host.indexOf(',')).trimRight();
|
||||
}
|
||||
|
||||
if (!host) return;
|
||||
|
||||
// IPv6 literal support
|
||||
var offset = host[0] === '['
|
||||
? host.indexOf(']') + 1
|
||||
: 0;
|
||||
var offset = host[0] === '[' ? host.indexOf(']') + 1 : 0;
|
||||
var index = host.indexOf(':', offset);
|
||||
|
||||
return index !== -1
|
||||
? host.substring(0, index)
|
||||
: host;
|
||||
return index !== -1 ? host.substring(0, index) : host;
|
||||
});
|
||||
|
||||
// TODO: change req.host to return host in next major
|
||||
|
||||
defineGetter(req, 'host', deprecate.function(function host(){
|
||||
return this.hostname;
|
||||
}, 'req.host: Use req.hostname instead'));
|
||||
defineGetter(
|
||||
req,
|
||||
'host',
|
||||
deprecate.function(function host() {
|
||||
return this.hostname;
|
||||
}, 'req.host: Use req.hostname instead')
|
||||
);
|
||||
|
||||
/**
|
||||
* Check if the request is fresh, aka
|
||||
@ -464,10 +462,10 @@ defineGetter(req, 'host', deprecate.function(function host(){
|
||||
* @public
|
||||
*/
|
||||
|
||||
defineGetter(req, 'fresh', function(){
|
||||
defineGetter(req, 'fresh', function () {
|
||||
var method = this.method;
|
||||
var res = this.res
|
||||
var status = res.statusCode
|
||||
var res = this.res;
|
||||
var status = res.statusCode;
|
||||
|
||||
// GET or HEAD for weak freshness validation only
|
||||
if ('GET' !== method && 'HEAD' !== method) return false;
|
||||
@ -475,9 +473,9 @@ defineGetter(req, 'fresh', function(){
|
||||
// 2xx or 304 as per rfc2616 14.26
|
||||
if ((status >= 200 && status < 300) || 304 === status) {
|
||||
return fresh(this.headers, {
|
||||
'etag': res.get('ETag'),
|
||||
'last-modified': res.get('Last-Modified')
|
||||
})
|
||||
etag: res.get('ETag'),
|
||||
'last-modified': res.get('Last-Modified'),
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -492,7 +490,7 @@ defineGetter(req, 'fresh', function(){
|
||||
* @public
|
||||
*/
|
||||
|
||||
defineGetter(req, 'stale', function stale(){
|
||||
defineGetter(req, 'stale', function stale() {
|
||||
return !this.fresh;
|
||||
});
|
||||
|
||||
@ -503,7 +501,7 @@ defineGetter(req, 'stale', function stale(){
|
||||
* @public
|
||||
*/
|
||||
|
||||
defineGetter(req, 'xhr', function xhr(){
|
||||
defineGetter(req, 'xhr', function xhr() {
|
||||
var val = this.get('X-Requested-With') || '';
|
||||
return val.toLowerCase() === 'xmlhttprequest';
|
||||
});
|
||||
@ -520,6 +518,6 @@ function defineGetter(obj, name, getter) {
|
||||
Object.defineProperty(obj, name, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: getter
|
||||
get: getter,
|
||||
});
|
||||
}
|
||||
|
276
node_modules/express/lib/response.js
generated
vendored
276
node_modules/express/lib/response.js
generated
vendored
@ -12,9 +12,9 @@
|
||||
* @private
|
||||
*/
|
||||
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
var contentDisposition = require('content-disposition');
|
||||
var createError = require('http-errors')
|
||||
var createError = require('http-errors');
|
||||
var deprecate = require('depd')('express');
|
||||
var encodeUrl = require('encodeurl');
|
||||
var escapeHtml = require('escape-html');
|
||||
@ -22,7 +22,7 @@ var http = require('http');
|
||||
var isAbsolute = require('./utils').isAbsolute;
|
||||
var onFinished = require('on-finished');
|
||||
var path = require('path');
|
||||
var statuses = require('statuses')
|
||||
var statuses = require('statuses');
|
||||
var merge = require('utils-merge');
|
||||
var sign = require('cookie-signature').sign;
|
||||
var normalizeType = require('./utils').normalizeType;
|
||||
@ -40,14 +40,14 @@ var vary = require('vary');
|
||||
* @public
|
||||
*/
|
||||
|
||||
var res = Object.create(http.ServerResponse.prototype)
|
||||
var res = Object.create(http.ServerResponse.prototype);
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
* @public
|
||||
*/
|
||||
|
||||
module.exports = res
|
||||
module.exports = res;
|
||||
|
||||
/**
|
||||
* Module variables.
|
||||
@ -65,8 +65,18 @@ var charsetRegExp = /;\s*charset\s*=/;
|
||||
*/
|
||||
|
||||
res.status = function status(code) {
|
||||
if ((typeof code === 'string' || Math.floor(code) !== code) && code > 99 && code < 1000) {
|
||||
deprecate('res.status(' + JSON.stringify(code) + '): use res.status(' + Math.floor(code) + ') instead')
|
||||
if (
|
||||
(typeof code === 'string' || Math.floor(code) !== code) &&
|
||||
code > 99 &&
|
||||
code < 1000
|
||||
) {
|
||||
deprecate(
|
||||
'res.status(' +
|
||||
JSON.stringify(code) +
|
||||
'): use res.status(' +
|
||||
Math.floor(code) +
|
||||
') instead'
|
||||
);
|
||||
}
|
||||
this.statusCode = code;
|
||||
return this;
|
||||
@ -87,12 +97,18 @@ res.status = function status(code) {
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.links = function(links){
|
||||
res.links = function (links) {
|
||||
var link = this.get('Link') || '';
|
||||
if (link) link += ', ';
|
||||
return this.set('Link', link + Object.keys(links).map(function(rel){
|
||||
return '<' + links[rel] + '>; rel="' + rel + '"';
|
||||
}).join(', '));
|
||||
return this.set(
|
||||
'Link',
|
||||
link +
|
||||
Object.keys(links)
|
||||
.map(function (rel) {
|
||||
return '<' + links[rel] + '>; rel="' + rel + '"';
|
||||
})
|
||||
.join(', ')
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -121,10 +137,14 @@ res.send = function send(body) {
|
||||
if (arguments.length === 2) {
|
||||
// res.send(body, status) backwards compat
|
||||
if (typeof arguments[0] !== 'number' && typeof arguments[1] === 'number') {
|
||||
deprecate('res.send(body, status): Use res.status(status).send(body) instead');
|
||||
deprecate(
|
||||
'res.send(body, status): Use res.status(status).send(body) instead'
|
||||
);
|
||||
this.statusCode = arguments[1];
|
||||
} else {
|
||||
deprecate('res.send(status, body): Use res.status(status).send(body) instead');
|
||||
deprecate(
|
||||
'res.send(status, body): Use res.status(status).send(body) instead'
|
||||
);
|
||||
this.statusCode = arguments[0];
|
||||
chunk = arguments[1];
|
||||
}
|
||||
@ -139,7 +159,7 @@ res.send = function send(body) {
|
||||
|
||||
deprecate('res.send(status): Use res.sendStatus(status) instead');
|
||||
this.statusCode = chunk;
|
||||
chunk = statuses.message[chunk]
|
||||
chunk = statuses.message[chunk];
|
||||
}
|
||||
|
||||
switch (typeof chunk) {
|
||||
@ -176,23 +196,23 @@ res.send = function send(body) {
|
||||
}
|
||||
|
||||
// determine if ETag should be generated
|
||||
var etagFn = app.get('etag fn')
|
||||
var generateETag = !this.get('ETag') && typeof etagFn === 'function'
|
||||
var etagFn = app.get('etag fn');
|
||||
var generateETag = !this.get('ETag') && typeof etagFn === 'function';
|
||||
|
||||
// populate Content-Length
|
||||
var len
|
||||
var len;
|
||||
if (chunk !== undefined) {
|
||||
if (Buffer.isBuffer(chunk)) {
|
||||
// get length of Buffer
|
||||
len = chunk.length
|
||||
len = chunk.length;
|
||||
} else if (!generateETag && chunk.length < 1000) {
|
||||
// just calculate length when no ETag + small chunk
|
||||
len = Buffer.byteLength(chunk, encoding)
|
||||
len = Buffer.byteLength(chunk, encoding);
|
||||
} else {
|
||||
// convert chunk to Buffer and calculate
|
||||
chunk = Buffer.from(chunk, encoding)
|
||||
chunk = Buffer.from(chunk, encoding);
|
||||
encoding = undefined;
|
||||
len = chunk.length
|
||||
len = chunk.length;
|
||||
}
|
||||
|
||||
this.set('Content-Length', len);
|
||||
@ -219,9 +239,9 @@ res.send = function send(body) {
|
||||
|
||||
// alter headers for 205
|
||||
if (this.statusCode === 205) {
|
||||
this.set('Content-Length', '0')
|
||||
this.removeHeader('Transfer-Encoding')
|
||||
chunk = ''
|
||||
this.set('Content-Length', '0');
|
||||
this.removeHeader('Transfer-Encoding');
|
||||
chunk = '';
|
||||
}
|
||||
|
||||
if (req.method === 'HEAD') {
|
||||
@ -254,10 +274,14 @@ res.json = function json(obj) {
|
||||
if (arguments.length === 2) {
|
||||
// res.json(body, status) backwards compat
|
||||
if (typeof arguments[1] === 'number') {
|
||||
deprecate('res.json(obj, status): Use res.status(status).json(obj) instead');
|
||||
deprecate(
|
||||
'res.json(obj, status): Use res.status(status).json(obj) instead'
|
||||
);
|
||||
this.statusCode = arguments[1];
|
||||
} else {
|
||||
deprecate('res.json(status, obj): Use res.status(status).json(obj) instead');
|
||||
deprecate(
|
||||
'res.json(status, obj): Use res.status(status).json(obj) instead'
|
||||
);
|
||||
this.statusCode = arguments[0];
|
||||
val = arguments[1];
|
||||
}
|
||||
@ -265,10 +289,10 @@ res.json = function json(obj) {
|
||||
|
||||
// settings
|
||||
var app = this.app;
|
||||
var escape = app.get('json escape')
|
||||
var escape = app.get('json escape');
|
||||
var replacer = app.get('json replacer');
|
||||
var spaces = app.get('json spaces');
|
||||
var body = stringify(val, replacer, spaces, escape)
|
||||
var body = stringify(val, replacer, spaces, escape);
|
||||
|
||||
// content-type
|
||||
if (!this.get('Content-Type')) {
|
||||
@ -297,10 +321,14 @@ res.jsonp = function jsonp(obj) {
|
||||
if (arguments.length === 2) {
|
||||
// res.jsonp(body, status) backwards compat
|
||||
if (typeof arguments[1] === 'number') {
|
||||
deprecate('res.jsonp(obj, status): Use res.status(status).jsonp(obj) instead');
|
||||
deprecate(
|
||||
'res.jsonp(obj, status): Use res.status(status).jsonp(obj) instead'
|
||||
);
|
||||
this.statusCode = arguments[1];
|
||||
} else {
|
||||
deprecate('res.jsonp(status, obj): Use res.status(status).jsonp(obj) instead');
|
||||
deprecate(
|
||||
'res.jsonp(status, obj): Use res.status(status).jsonp(obj) instead'
|
||||
);
|
||||
this.statusCode = arguments[0];
|
||||
val = arguments[1];
|
||||
}
|
||||
@ -308,10 +336,10 @@ res.jsonp = function jsonp(obj) {
|
||||
|
||||
// settings
|
||||
var app = this.app;
|
||||
var escape = app.get('json escape')
|
||||
var escape = app.get('json escape');
|
||||
var replacer = app.get('json replacer');
|
||||
var spaces = app.get('json spaces');
|
||||
var body = stringify(val, replacer, spaces, escape)
|
||||
var body = stringify(val, replacer, spaces, escape);
|
||||
var callback = this.req.query[app.get('jsonp callback name')];
|
||||
|
||||
// content-type
|
||||
@ -335,17 +363,22 @@ res.jsonp = function jsonp(obj) {
|
||||
|
||||
if (body === undefined) {
|
||||
// empty argument
|
||||
body = ''
|
||||
body = '';
|
||||
} else if (typeof body === 'string') {
|
||||
// replace chars not allowed in JavaScript that are in JSON
|
||||
body = body
|
||||
.replace(/\u2028/g, '\\u2028')
|
||||
.replace(/\u2029/g, '\\u2029')
|
||||
body = body.replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
|
||||
}
|
||||
|
||||
// the /**/ is a specific security mitigation for "Rosetta Flash JSONP abuse"
|
||||
// the typeof check is just to reduce client error noise
|
||||
body = '/**/ typeof ' + callback + ' === \'function\' && ' + callback + '(' + body + ');';
|
||||
body =
|
||||
'/**/ typeof ' +
|
||||
callback +
|
||||
" === 'function' && " +
|
||||
callback +
|
||||
'(' +
|
||||
body +
|
||||
');';
|
||||
}
|
||||
|
||||
return this.send(body);
|
||||
@ -367,7 +400,7 @@ res.jsonp = function jsonp(obj) {
|
||||
*/
|
||||
|
||||
res.sendStatus = function sendStatus(statusCode) {
|
||||
var body = statuses.message[statusCode] || String(statusCode)
|
||||
var body = statuses.message[statusCode] || String(statusCode);
|
||||
|
||||
this.statusCode = statusCode;
|
||||
this.type('txt');
|
||||
@ -428,7 +461,7 @@ res.sendFile = function sendFile(path, options, callback) {
|
||||
}
|
||||
|
||||
if (typeof path !== 'string') {
|
||||
throw new TypeError('path must be a string to res.sendFile')
|
||||
throw new TypeError('path must be a string to res.sendFile');
|
||||
}
|
||||
|
||||
// support function as second arg
|
||||
@ -438,7 +471,9 @@ res.sendFile = function sendFile(path, options, callback) {
|
||||
}
|
||||
|
||||
if (!opts.root && !isAbsolute(path)) {
|
||||
throw new TypeError('path must be absolute or specify root to res.sendFile');
|
||||
throw new TypeError(
|
||||
'path must be absolute or specify root to res.sendFile'
|
||||
);
|
||||
}
|
||||
|
||||
// create file stream
|
||||
@ -526,8 +561,10 @@ res.sendfile = function (path, options, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
res.sendfile = deprecate.function(res.sendfile,
|
||||
'res.sendfile: Use res.sendFile instead');
|
||||
res.sendfile = deprecate.function(
|
||||
res.sendfile,
|
||||
'res.sendfile: Use res.sendFile instead'
|
||||
);
|
||||
|
||||
/**
|
||||
* Transfer the file at the given `path` as an attachment.
|
||||
@ -547,55 +584,55 @@ res.sendfile = deprecate.function(res.sendfile,
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.download = function download (path, filename, options, callback) {
|
||||
res.download = function download(path, filename, options, callback) {
|
||||
var done = callback;
|
||||
var name = filename;
|
||||
var opts = options || null
|
||||
var opts = options || null;
|
||||
|
||||
// support function as second or third arg
|
||||
if (typeof filename === 'function') {
|
||||
done = filename;
|
||||
name = null;
|
||||
opts = null
|
||||
opts = null;
|
||||
} else if (typeof options === 'function') {
|
||||
done = options
|
||||
opts = null
|
||||
done = options;
|
||||
opts = null;
|
||||
}
|
||||
|
||||
// support optional filename, where options may be in it's place
|
||||
if (typeof filename === 'object' &&
|
||||
(typeof options === 'function' || options === undefined)) {
|
||||
name = null
|
||||
opts = filename
|
||||
if (
|
||||
typeof filename === 'object' &&
|
||||
(typeof options === 'function' || options === undefined)
|
||||
) {
|
||||
name = null;
|
||||
opts = filename;
|
||||
}
|
||||
|
||||
// set Content-Disposition when file is sent
|
||||
var headers = {
|
||||
'Content-Disposition': contentDisposition(name || path)
|
||||
'Content-Disposition': contentDisposition(name || path),
|
||||
};
|
||||
|
||||
// merge user-provided headers
|
||||
if (opts && opts.headers) {
|
||||
var keys = Object.keys(opts.headers)
|
||||
var keys = Object.keys(opts.headers);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i]
|
||||
var key = keys[i];
|
||||
if (key.toLowerCase() !== 'content-disposition') {
|
||||
headers[key] = opts.headers[key]
|
||||
headers[key] = opts.headers[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// merge user-provided options
|
||||
opts = Object.create(opts)
|
||||
opts.headers = headers
|
||||
opts = Object.create(opts);
|
||||
opts.headers = headers;
|
||||
|
||||
// Resolve the full path for sendFile
|
||||
var fullPath = !opts.root
|
||||
? resolve(path)
|
||||
: path
|
||||
var fullPath = !opts.root ? resolve(path) : path;
|
||||
|
||||
// send file
|
||||
return this.sendFile(fullPath, opts, done)
|
||||
return this.sendFile(fullPath, opts, done);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -615,11 +652,8 @@ res.download = function download (path, filename, options, callback) {
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.contentType =
|
||||
res.type = function contentType(type) {
|
||||
var ct = type.indexOf('/') === -1
|
||||
? mime.lookup(type)
|
||||
: type;
|
||||
res.contentType = res.type = function contentType(type) {
|
||||
var ct = type.indexOf('/') === -1 ? mime.lookup(type) : type;
|
||||
|
||||
return this.set('Content-Type', ct);
|
||||
};
|
||||
@ -681,28 +715,31 @@ res.type = function contentType(type) {
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.format = function(obj){
|
||||
res.format = function (obj) {
|
||||
var req = this.req;
|
||||
var next = req.next;
|
||||
|
||||
var keys = Object.keys(obj)
|
||||
.filter(function (v) { return v !== 'default' })
|
||||
var keys = Object.keys(obj).filter(function (v) {
|
||||
return v !== 'default';
|
||||
});
|
||||
|
||||
var key = keys.length > 0
|
||||
? req.accepts(keys)
|
||||
: false;
|
||||
var key = keys.length > 0 ? req.accepts(keys) : false;
|
||||
|
||||
this.vary("Accept");
|
||||
this.vary('Accept');
|
||||
|
||||
if (key) {
|
||||
this.set('Content-Type', normalizeType(key).value);
|
||||
obj[key](req, this, next);
|
||||
} else if (obj.default) {
|
||||
obj.default(req, this, next)
|
||||
obj.default(req, this, next);
|
||||
} else {
|
||||
next(createError(406, {
|
||||
types: normalizeTypes(keys).map(function (o) { return o.value })
|
||||
}))
|
||||
next(
|
||||
createError(406, {
|
||||
types: normalizeTypes(keys).map(function (o) {
|
||||
return o.value;
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -747,9 +784,10 @@ res.append = function append(field, val) {
|
||||
|
||||
if (prev) {
|
||||
// concat the new and prev vals
|
||||
value = Array.isArray(prev) ? prev.concat(val)
|
||||
value =
|
||||
Array.isArray(prev) ? prev.concat(val)
|
||||
: Array.isArray(val) ? [prev].concat(val)
|
||||
: [prev, val]
|
||||
: [prev, val];
|
||||
}
|
||||
|
||||
return this.set(field, value);
|
||||
@ -773,12 +811,9 @@ res.append = function append(field, val) {
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.set =
|
||||
res.header = function header(field, val) {
|
||||
res.set = res.header = function header(field, val) {
|
||||
if (arguments.length === 2) {
|
||||
var value = Array.isArray(val)
|
||||
? val.map(String)
|
||||
: String(val);
|
||||
var value = Array.isArray(val) ? val.map(String) : String(val);
|
||||
|
||||
// add charset to content-type
|
||||
if (field.toLowerCase() === 'content-type') {
|
||||
@ -808,7 +843,7 @@ res.header = function header(field, val) {
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.get = function(field){
|
||||
res.get = function (field) {
|
||||
return this.getHeader(field);
|
||||
};
|
||||
|
||||
@ -824,10 +859,14 @@ res.get = function(field){
|
||||
res.clearCookie = function clearCookie(name, options) {
|
||||
if (options) {
|
||||
if (options.maxAge) {
|
||||
deprecate('res.clearCookie: Passing "options.maxAge" is deprecated. In v5.0.0 of Express, this option will be ignored, as res.clearCookie will automatically set cookies to expire immediately. Please update your code to omit this option.');
|
||||
deprecate(
|
||||
'res.clearCookie: Passing "options.maxAge" is deprecated. In v5.0.0 of Express, this option will be ignored, as res.clearCookie will automatically set cookies to expire immediately. Please update your code to omit this option.'
|
||||
);
|
||||
}
|
||||
if (options.expires) {
|
||||
deprecate('res.clearCookie: Passing "options.expires" is deprecated. In v5.0.0 of Express, this option will be ignored, as res.clearCookie will automatically set cookies to expire immediately. Please update your code to omit this option.');
|
||||
deprecate(
|
||||
'res.clearCookie: Passing "options.expires" is deprecated. In v5.0.0 of Express, this option will be ignored, as res.clearCookie will automatically set cookies to expire immediately. Please update your code to omit this option.'
|
||||
);
|
||||
}
|
||||
}
|
||||
var opts = merge({ expires: new Date(1), path: '/' }, options);
|
||||
@ -868,20 +907,19 @@ res.cookie = function (name, value, options) {
|
||||
throw new Error('cookieParser("secret") required for signed cookies');
|
||||
}
|
||||
|
||||
var val = typeof value === 'object'
|
||||
? 'j:' + JSON.stringify(value)
|
||||
: String(value);
|
||||
var val =
|
||||
typeof value === 'object' ? 'j:' + JSON.stringify(value) : String(value);
|
||||
|
||||
if (signed) {
|
||||
val = 's:' + sign(val, secret);
|
||||
}
|
||||
|
||||
if (opts.maxAge != null) {
|
||||
var maxAge = opts.maxAge - 0
|
||||
var maxAge = opts.maxAge - 0;
|
||||
|
||||
if (!isNaN(maxAge)) {
|
||||
opts.expires = new Date(Date.now() + maxAge)
|
||||
opts.maxAge = Math.floor(maxAge / 1000)
|
||||
opts.expires = new Date(Date.now() + maxAge);
|
||||
opts.maxAge = Math.floor(maxAge / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -916,7 +954,9 @@ res.location = function location(url) {
|
||||
|
||||
// "back" is an alias for the referrer
|
||||
if (url === 'back') {
|
||||
deprecate('res.location("back"): use res.location(req.get("Referrer") || "/") and refer to https://dub.sh/security-redirect for best practices');
|
||||
deprecate(
|
||||
'res.location("back"): use res.location(req.get("Referrer") || "/") and refer to https://dub.sh/security-redirect for best practices'
|
||||
);
|
||||
loc = this.req.get('Referrer') || '/';
|
||||
} else {
|
||||
loc = String(url);
|
||||
@ -954,7 +994,9 @@ res.redirect = function redirect(url) {
|
||||
status = arguments[0];
|
||||
address = arguments[1];
|
||||
} else {
|
||||
deprecate('res.redirect(url, status): Use res.redirect(status, url) instead');
|
||||
deprecate(
|
||||
'res.redirect(url, status): Use res.redirect(status, url) instead'
|
||||
);
|
||||
status = arguments[1];
|
||||
}
|
||||
}
|
||||
@ -964,18 +1006,19 @@ res.redirect = function redirect(url) {
|
||||
|
||||
// Support text/{plain,html} by default
|
||||
this.format({
|
||||
text: function(){
|
||||
body = statuses.message[status] + '. Redirecting to ' + address
|
||||
text: function () {
|
||||
body = statuses.message[status] + '. Redirecting to ' + address;
|
||||
},
|
||||
|
||||
html: function(){
|
||||
html: function () {
|
||||
var u = escapeHtml(address);
|
||||
body = '<p>' + statuses.message[status] + '. Redirecting to ' + u + '</p>'
|
||||
body =
|
||||
'<p>' + statuses.message[status] + '. Redirecting to ' + u + '</p>';
|
||||
},
|
||||
|
||||
default: function(){
|
||||
default: function () {
|
||||
body = '';
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// Respond
|
||||
@ -998,7 +1041,7 @@ res.redirect = function redirect(url) {
|
||||
* @public
|
||||
*/
|
||||
|
||||
res.vary = function(field){
|
||||
res.vary = function (field) {
|
||||
// checks for back-compat
|
||||
if (!field || (Array.isArray(field) && !field.length)) {
|
||||
deprecate('res.vary(): Provide a field name');
|
||||
@ -1040,10 +1083,12 @@ res.render = function render(view, options, callback) {
|
||||
opts._locals = self.locals;
|
||||
|
||||
// default callback to respond
|
||||
done = done || function (err, str) {
|
||||
if (err) return req.next(err);
|
||||
self.send(str);
|
||||
};
|
||||
done =
|
||||
done ||
|
||||
function (err, str) {
|
||||
if (err) return req.next(err);
|
||||
self.send(str);
|
||||
};
|
||||
|
||||
// render
|
||||
app.render(view, opts, done);
|
||||
@ -1152,28 +1197,29 @@ function sendfile(res, file, options, callback) {
|
||||
* @private
|
||||
*/
|
||||
|
||||
function stringify (value, replacer, spaces, escape) {
|
||||
function stringify(value, replacer, spaces, escape) {
|
||||
// v8 checks arguments.length for optimizing simple call
|
||||
// https://bugs.chromium.org/p/v8/issues/detail?id=4730
|
||||
var json = replacer || spaces
|
||||
? JSON.stringify(value, replacer, spaces)
|
||||
var json =
|
||||
replacer || spaces ?
|
||||
JSON.stringify(value, replacer, spaces)
|
||||
: JSON.stringify(value);
|
||||
|
||||
if (escape && typeof json === 'string') {
|
||||
json = json.replace(/[<>&]/g, function (c) {
|
||||
switch (c.charCodeAt(0)) {
|
||||
case 0x3c:
|
||||
return '\\u003c'
|
||||
return '\\u003c';
|
||||
case 0x3e:
|
||||
return '\\u003e'
|
||||
return '\\u003e';
|
||||
case 0x26:
|
||||
return '\\u0026'
|
||||
return '\\u0026';
|
||||
/* istanbul ignore next: unreachable default */
|
||||
default:
|
||||
return c
|
||||
return c;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
return json
|
||||
return json;
|
||||
}
|
||||
|
141
node_modules/express/lib/router/index.js
generated
vendored
141
node_modules/express/lib/router/index.js
generated
vendored
@ -21,7 +21,7 @@ var debug = require('debug')('express:router');
|
||||
var deprecate = require('depd')('express');
|
||||
var flatten = require('array-flatten');
|
||||
var parseUrl = require('parseurl');
|
||||
var setPrototypeOf = require('setprototypeof')
|
||||
var setPrototypeOf = require('setprototypeof');
|
||||
|
||||
/**
|
||||
* Module variables.
|
||||
@ -40,7 +40,7 @@ var toString = Object.prototype.toString;
|
||||
* @public
|
||||
*/
|
||||
|
||||
var proto = module.exports = function(options) {
|
||||
var proto = (module.exports = function (options) {
|
||||
var opts = options || {};
|
||||
|
||||
function router(req, res, next) {
|
||||
@ -48,7 +48,7 @@ var proto = module.exports = function(options) {
|
||||
}
|
||||
|
||||
// mixin Router class functions
|
||||
setPrototypeOf(router, proto)
|
||||
setPrototypeOf(router, proto);
|
||||
|
||||
router.params = {};
|
||||
router._params = [];
|
||||
@ -58,7 +58,7 @@ var proto = module.exports = function(options) {
|
||||
router.stack = [];
|
||||
|
||||
return router;
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* Map the given param placeholder `name`(s) to the given callback.
|
||||
@ -108,12 +108,18 @@ proto.param = function param(name, fn) {
|
||||
var ret;
|
||||
|
||||
if (name[0] === ':') {
|
||||
deprecate('router.param(' + JSON.stringify(name) + ', fn): Use router.param(' + JSON.stringify(name.slice(1)) + ', fn) instead')
|
||||
name = name.slice(1)
|
||||
deprecate(
|
||||
'router.param(' +
|
||||
JSON.stringify(name) +
|
||||
', fn): Use router.param(' +
|
||||
JSON.stringify(name.slice(1)) +
|
||||
', fn) instead'
|
||||
);
|
||||
name = name.slice(1);
|
||||
}
|
||||
|
||||
for (var i = 0; i < len; ++i) {
|
||||
if (ret = params[i](name, fn)) {
|
||||
if ((ret = params[i](name, fn))) {
|
||||
fn = ret;
|
||||
}
|
||||
}
|
||||
@ -139,10 +145,10 @@ proto.handle = function handle(req, res, out) {
|
||||
debug('dispatching %s %s', req.method, req.url);
|
||||
|
||||
var idx = 0;
|
||||
var protohost = getProtohost(req.url) || ''
|
||||
var protohost = getProtohost(req.url) || '';
|
||||
var removed = '';
|
||||
var slashAdded = false;
|
||||
var sync = 0
|
||||
var sync = 0;
|
||||
var paramcalled = {};
|
||||
|
||||
// store options for OPTIONS request
|
||||
@ -162,7 +168,7 @@ proto.handle = function handle(req, res, out) {
|
||||
|
||||
// for options requests, respond with a default if nothing else responds
|
||||
if (req.method === 'OPTIONS') {
|
||||
done = wrap(done, function(old, err) {
|
||||
done = wrap(done, function (old, err) {
|
||||
if (err || options.length === 0) return old(err);
|
||||
sendOptionsResponse(res, options, old);
|
||||
});
|
||||
@ -175,27 +181,25 @@ proto.handle = function handle(req, res, out) {
|
||||
next();
|
||||
|
||||
function next(err) {
|
||||
var layerError = err === 'route'
|
||||
? null
|
||||
: err;
|
||||
var layerError = err === 'route' ? null : err;
|
||||
|
||||
// remove added slash
|
||||
if (slashAdded) {
|
||||
req.url = req.url.slice(1)
|
||||
req.url = req.url.slice(1);
|
||||
slashAdded = false;
|
||||
}
|
||||
|
||||
// restore altered req.url
|
||||
if (removed.length !== 0) {
|
||||
req.baseUrl = parentUrl;
|
||||
req.url = protohost + removed + req.url.slice(protohost.length)
|
||||
req.url = protohost + removed + req.url.slice(protohost.length);
|
||||
removed = '';
|
||||
}
|
||||
|
||||
// signal to exit router
|
||||
if (layerError === 'router') {
|
||||
setImmediate(done, null)
|
||||
return
|
||||
setImmediate(done, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// no more matching layers
|
||||
@ -206,7 +210,7 @@ proto.handle = function handle(req, res, out) {
|
||||
|
||||
// max sync stack
|
||||
if (++sync > 100) {
|
||||
return setImmediate(next, err)
|
||||
return setImmediate(next, err);
|
||||
}
|
||||
|
||||
// get pathname of request
|
||||
@ -271,22 +275,21 @@ proto.handle = function handle(req, res, out) {
|
||||
}
|
||||
|
||||
// Capture one-time layer values
|
||||
req.params = self.mergeParams
|
||||
? mergeParams(layer.params, parentParams)
|
||||
: layer.params;
|
||||
req.params =
|
||||
self.mergeParams ? mergeParams(layer.params, parentParams) : layer.params;
|
||||
var layerPath = layer.path;
|
||||
|
||||
// this should be done for the layer
|
||||
self.process_params(layer, paramcalled, req, res, function (err) {
|
||||
if (err) {
|
||||
next(layerError || err)
|
||||
next(layerError || err);
|
||||
} else if (route) {
|
||||
layer.handle_request(req, res, next)
|
||||
layer.handle_request(req, res, next);
|
||||
} else {
|
||||
trim_prefix(layer, layerError, layerPath, path)
|
||||
trim_prefix(layer, layerError, layerPath, path);
|
||||
}
|
||||
|
||||
sync = 0
|
||||
sync = 0;
|
||||
});
|
||||
}
|
||||
|
||||
@ -294,19 +297,19 @@ proto.handle = function handle(req, res, out) {
|
||||
if (layerPath.length !== 0) {
|
||||
// Validate path is a prefix match
|
||||
if (layerPath !== path.slice(0, layerPath.length)) {
|
||||
next(layerError)
|
||||
return
|
||||
next(layerError);
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate path breaks on a path separator
|
||||
var c = path[layerPath.length]
|
||||
if (c && c !== '/' && c !== '.') return next(layerError)
|
||||
var c = path[layerPath.length];
|
||||
if (c && c !== '/' && c !== '.') return next(layerError);
|
||||
|
||||
// Trim off the part of the url that matches the route
|
||||
// middleware (.use stuff) needs to have the path stripped
|
||||
debug('trim prefix (%s) from url %s', layerPath, req.url);
|
||||
removed = layerPath;
|
||||
req.url = protohost + req.url.slice(protohost.length + removed.length)
|
||||
req.url = protohost + req.url.slice(protohost.length + removed.length);
|
||||
|
||||
// Ensure leading slash
|
||||
if (!protohost && req.url[0] !== '/') {
|
||||
@ -315,8 +318,10 @@ proto.handle = function handle(req, res, out) {
|
||||
}
|
||||
|
||||
// Setup base URL (no trailing slash)
|
||||
req.baseUrl = parentUrl + (removed[removed.length - 1] === '/'
|
||||
? removed.substring(0, removed.length - 1)
|
||||
req.baseUrl =
|
||||
parentUrl +
|
||||
(removed[removed.length - 1] === '/' ?
|
||||
removed.substring(0, removed.length - 1)
|
||||
: removed);
|
||||
}
|
||||
|
||||
@ -361,7 +366,7 @@ proto.process_params = function process_params(layer, called, req, res, done) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
if (i >= keys.length ) {
|
||||
if (i >= keys.length) {
|
||||
return done();
|
||||
}
|
||||
|
||||
@ -377,8 +382,11 @@ proto.process_params = function process_params(layer, called, req, res, done) {
|
||||
}
|
||||
|
||||
// param previously called with same value or error occurred
|
||||
if (paramCalled && (paramCalled.match === paramVal
|
||||
|| (paramCalled.error && paramCalled.error !== 'route'))) {
|
||||
if (
|
||||
paramCalled &&
|
||||
(paramCalled.match === paramVal ||
|
||||
(paramCalled.error && paramCalled.error !== 'route'))
|
||||
) {
|
||||
// restore value
|
||||
req.params[name] = paramCalled.value;
|
||||
|
||||
@ -389,7 +397,7 @@ proto.process_params = function process_params(layer, called, req, res, done) {
|
||||
called[name] = paramCalled = {
|
||||
error: null,
|
||||
match: paramVal,
|
||||
value: paramVal
|
||||
value: paramVal,
|
||||
};
|
||||
|
||||
paramCallback();
|
||||
@ -459,24 +467,30 @@ proto.use = function use(fn) {
|
||||
var callbacks = flatten(slice.call(arguments, offset));
|
||||
|
||||
if (callbacks.length === 0) {
|
||||
throw new TypeError('Router.use() requires a middleware function')
|
||||
throw new TypeError('Router.use() requires a middleware function');
|
||||
}
|
||||
|
||||
for (var i = 0; i < callbacks.length; i++) {
|
||||
var fn = callbacks[i];
|
||||
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
|
||||
throw new TypeError(
|
||||
'Router.use() requires a middleware function but got a ' + gettype(fn)
|
||||
);
|
||||
}
|
||||
|
||||
// add the middleware
|
||||
debug('use %o %s', path, fn.name || '<anonymous>')
|
||||
debug('use %o %s', path, fn.name || '<anonymous>');
|
||||
|
||||
var layer = new Layer(path, {
|
||||
sensitive: this.caseSensitive,
|
||||
strict: false,
|
||||
end: false
|
||||
}, fn);
|
||||
var layer = new Layer(
|
||||
path,
|
||||
{
|
||||
sensitive: this.caseSensitive,
|
||||
strict: false,
|
||||
end: false,
|
||||
},
|
||||
fn
|
||||
);
|
||||
|
||||
layer.route = undefined;
|
||||
|
||||
@ -502,11 +516,15 @@ proto.use = function use(fn) {
|
||||
proto.route = function route(path) {
|
||||
var route = new Route(path);
|
||||
|
||||
var layer = new Layer(path, {
|
||||
sensitive: this.caseSensitive,
|
||||
strict: this.strict,
|
||||
end: true
|
||||
}, route.dispatch.bind(route));
|
||||
var layer = new Layer(
|
||||
path,
|
||||
{
|
||||
sensitive: this.caseSensitive,
|
||||
strict: this.strict,
|
||||
end: true,
|
||||
},
|
||||
route.dispatch.bind(route)
|
||||
);
|
||||
|
||||
layer.route = route;
|
||||
|
||||
@ -515,9 +533,9 @@ proto.route = function route(path) {
|
||||
};
|
||||
|
||||
// create Router#VERB functions
|
||||
methods.concat('all').forEach(function(method){
|
||||
proto[method] = function(path){
|
||||
var route = this.route(path)
|
||||
methods.concat('all').forEach(function (method) {
|
||||
proto[method] = function (path) {
|
||||
var route = this.route(path);
|
||||
route[method].apply(route, slice.call(arguments, 1));
|
||||
return this;
|
||||
};
|
||||
@ -545,18 +563,16 @@ function getPathname(req) {
|
||||
// Get get protocol + host for a URL
|
||||
function getProtohost(url) {
|
||||
if (typeof url !== 'string' || url.length === 0 || url[0] === '/') {
|
||||
return undefined
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var searchIndex = url.indexOf('?')
|
||||
var pathLength = searchIndex !== -1
|
||||
? searchIndex
|
||||
: url.length
|
||||
var fqdnIndex = url.slice(0, pathLength).indexOf('://')
|
||||
var searchIndex = url.indexOf('?');
|
||||
var pathLength = searchIndex !== -1 ? searchIndex : url.length;
|
||||
var fqdnIndex = url.slice(0, pathLength).indexOf('://');
|
||||
|
||||
return fqdnIndex !== -1
|
||||
? url.substring(0, url.indexOf('/', 3 + fqdnIndex))
|
||||
: undefined
|
||||
return fqdnIndex !== -1 ?
|
||||
url.substring(0, url.indexOf('/', 3 + fqdnIndex))
|
||||
: undefined;
|
||||
}
|
||||
|
||||
// get type for error message
|
||||
@ -568,8 +584,7 @@ function gettype(obj) {
|
||||
}
|
||||
|
||||
// inspect [[Class]] for objects
|
||||
return toString.call(obj)
|
||||
.replace(objectRegExp, '$1');
|
||||
return toString.call(obj).replace(objectRegExp, '$1');
|
||||
}
|
||||
|
||||
/**
|
||||
|
32
node_modules/express/lib/router/layer.js
generated
vendored
32
node_modules/express/lib/router/layer.js
generated
vendored
@ -35,18 +35,18 @@ function Layer(path, options, fn) {
|
||||
return new Layer(path, options, fn);
|
||||
}
|
||||
|
||||
debug('new %o', path)
|
||||
debug('new %o', path);
|
||||
var opts = options || {};
|
||||
|
||||
this.handle = fn;
|
||||
this.name = fn.name || '<anonymous>';
|
||||
this.params = undefined;
|
||||
this.path = undefined;
|
||||
this.regexp = pathRegexp(path, this.keys = [], opts);
|
||||
this.regexp = pathRegexp(path, (this.keys = []), opts);
|
||||
|
||||
// set fast path flags
|
||||
this.regexp.fast_star = path === '*'
|
||||
this.regexp.fast_slash = path === '/' && opts.end === false
|
||||
this.regexp.fast_star = path === '*';
|
||||
this.regexp.fast_slash = path === '/' && opts.end === false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,25 +108,25 @@ Layer.prototype.handle_request = function handle(req, res, next) {
|
||||
*/
|
||||
|
||||
Layer.prototype.match = function match(path) {
|
||||
var match
|
||||
var match;
|
||||
|
||||
if (path != null) {
|
||||
// fast path non-ending match for / (any path matches)
|
||||
if (this.regexp.fast_slash) {
|
||||
this.params = {}
|
||||
this.path = ''
|
||||
return true
|
||||
this.params = {};
|
||||
this.path = '';
|
||||
return true;
|
||||
}
|
||||
|
||||
// fast path for * (everything matched in a param)
|
||||
if (this.regexp.fast_star) {
|
||||
this.params = {'0': decode_param(path)}
|
||||
this.path = path
|
||||
return true
|
||||
this.params = { 0: decode_param(path) };
|
||||
this.path = path;
|
||||
return true;
|
||||
}
|
||||
|
||||
// match the path
|
||||
match = this.regexp.exec(path)
|
||||
match = this.regexp.exec(path);
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
@ -137,7 +137,7 @@ Layer.prototype.match = function match(path) {
|
||||
|
||||
// store values
|
||||
this.params = {};
|
||||
this.path = match[0]
|
||||
this.path = match[0];
|
||||
|
||||
var keys = this.keys;
|
||||
var params = this.params;
|
||||
@ -145,9 +145,9 @@ Layer.prototype.match = function match(path) {
|
||||
for (var i = 1; i < match.length; i++) {
|
||||
var key = keys[i - 1];
|
||||
var prop = key.name;
|
||||
var val = decode_param(match[i])
|
||||
var val = decode_param(match[i]);
|
||||
|
||||
if (val !== undefined || !(hasOwnProperty.call(params, prop))) {
|
||||
if (val !== undefined || !hasOwnProperty.call(params, prop)) {
|
||||
params[prop] = val;
|
||||
}
|
||||
}
|
||||
@ -172,7 +172,7 @@ function decode_param(val) {
|
||||
return decodeURIComponent(val);
|
||||
} catch (err) {
|
||||
if (err instanceof URIError) {
|
||||
err.message = 'Failed to decode param \'' + val + '\'';
|
||||
err.message = "Failed to decode param '" + val + "'";
|
||||
err.status = err.statusCode = 400;
|
||||
}
|
||||
|
||||
|
39
node_modules/express/lib/router/route.js
generated
vendored
39
node_modules/express/lib/router/route.js
generated
vendored
@ -44,7 +44,7 @@ function Route(path) {
|
||||
this.path = path;
|
||||
this.stack = [];
|
||||
|
||||
debug('new %o', path)
|
||||
debug('new %o', path);
|
||||
|
||||
// route handlers for various http methods
|
||||
this.methods = {};
|
||||
@ -61,9 +61,7 @@ Route.prototype._handles_method = function _handles_method(method) {
|
||||
}
|
||||
|
||||
// normalize name
|
||||
var name = typeof method === 'string'
|
||||
? method.toLowerCase()
|
||||
: method
|
||||
var name = typeof method === 'string' ? method.toLowerCase() : method;
|
||||
|
||||
if (name === 'head' && !this.methods['head']) {
|
||||
name = 'get';
|
||||
@ -101,14 +99,13 @@ Route.prototype._options = function _options() {
|
||||
Route.prototype.dispatch = function dispatch(req, res, done) {
|
||||
var idx = 0;
|
||||
var stack = this.stack;
|
||||
var sync = 0
|
||||
var sync = 0;
|
||||
|
||||
if (stack.length === 0) {
|
||||
return done();
|
||||
}
|
||||
var method = typeof req.method === 'string'
|
||||
? req.method.toLowerCase()
|
||||
: req.method
|
||||
var method =
|
||||
typeof req.method === 'string' ? req.method.toLowerCase() : req.method;
|
||||
|
||||
if (method === 'head' && !this.methods['head']) {
|
||||
method = 'get';
|
||||
@ -126,30 +123,30 @@ Route.prototype.dispatch = function dispatch(req, res, done) {
|
||||
|
||||
// signal to exit router
|
||||
if (err && err === 'router') {
|
||||
return done(err)
|
||||
return done(err);
|
||||
}
|
||||
|
||||
// max sync stack
|
||||
if (++sync > 100) {
|
||||
return setImmediate(next, err)
|
||||
return setImmediate(next, err);
|
||||
}
|
||||
|
||||
var layer = stack[idx++]
|
||||
var layer = stack[idx++];
|
||||
|
||||
// end of layers
|
||||
if (!layer) {
|
||||
return done(err)
|
||||
return done(err);
|
||||
}
|
||||
|
||||
if (layer.method && layer.method !== method) {
|
||||
next(err)
|
||||
next(err);
|
||||
} else if (err) {
|
||||
layer.handle_error(err, req, res, next);
|
||||
} else {
|
||||
layer.handle_request(req, res, next);
|
||||
}
|
||||
|
||||
sync = 0
|
||||
sync = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@ -189,7 +186,7 @@ Route.prototype.all = function all() {
|
||||
|
||||
if (typeof handle !== 'function') {
|
||||
var type = toString.call(handle);
|
||||
var msg = 'Route.all() requires a callback function but got a ' + type
|
||||
var msg = 'Route.all() requires a callback function but got a ' + type;
|
||||
throw new TypeError(msg);
|
||||
}
|
||||
|
||||
@ -203,8 +200,8 @@ Route.prototype.all = function all() {
|
||||
return this;
|
||||
};
|
||||
|
||||
methods.forEach(function(method){
|
||||
Route.prototype[method] = function(){
|
||||
methods.forEach(function (method) {
|
||||
Route.prototype[method] = function () {
|
||||
var handles = flatten(slice.call(arguments));
|
||||
|
||||
for (var i = 0; i < handles.length; i++) {
|
||||
@ -212,11 +209,15 @@ methods.forEach(function(method){
|
||||
|
||||
if (typeof handle !== 'function') {
|
||||
var type = toString.call(handle);
|
||||
var msg = 'Route.' + method + '() requires a callback function but got a ' + type
|
||||
var msg =
|
||||
'Route.' +
|
||||
method +
|
||||
'() requires a callback function but got a ' +
|
||||
type;
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
debug('%s %o', method, this.path)
|
||||
debug('%s %o', method, this.path);
|
||||
|
||||
var layer = Layer('/', {}, handle);
|
||||
layer.method = method;
|
||||
|
69
node_modules/express/lib/utils.js
generated
vendored
69
node_modules/express/lib/utils.js
generated
vendored
@ -12,7 +12,7 @@
|
||||
* @api private
|
||||
*/
|
||||
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
var contentDisposition = require('content-disposition');
|
||||
var contentType = require('content-type');
|
||||
var deprecate = require('depd')('express');
|
||||
@ -32,7 +32,7 @@ var querystring = require('querystring');
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.etag = createETagGenerator({ weak: false })
|
||||
exports.etag = createETagGenerator({ weak: false });
|
||||
|
||||
/**
|
||||
* Return weak ETag for `body`.
|
||||
@ -43,7 +43,7 @@ exports.etag = createETagGenerator({ weak: false })
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.wetag = createETagGenerator({ weak: true })
|
||||
exports.wetag = createETagGenerator({ weak: true });
|
||||
|
||||
/**
|
||||
* Check if `path` looks absolute.
|
||||
@ -53,7 +53,7 @@ exports.wetag = createETagGenerator({ weak: true })
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.isAbsolute = function(path){
|
||||
exports.isAbsolute = function (path) {
|
||||
if ('/' === path[0]) return true;
|
||||
if (':' === path[1] && ('\\' === path[2] || '/' === path[2])) return true; // Windows device path
|
||||
if ('\\\\' === path.substring(0, 2)) return true; // Microsoft Azure absolute path
|
||||
@ -67,8 +67,10 @@ exports.isAbsolute = function(path){
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.flatten = deprecate.function(flatten,
|
||||
'utils.flatten: use array-flatten npm module instead');
|
||||
exports.flatten = deprecate.function(
|
||||
flatten,
|
||||
'utils.flatten: use array-flatten npm module instead'
|
||||
);
|
||||
|
||||
/**
|
||||
* Normalize the given `type`, for example "html" becomes "text/html".
|
||||
@ -78,9 +80,9 @@ exports.flatten = deprecate.function(flatten,
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.normalizeType = function(type){
|
||||
return ~type.indexOf('/')
|
||||
? acceptParams(type)
|
||||
exports.normalizeType = function (type) {
|
||||
return ~type.indexOf('/') ?
|
||||
acceptParams(type)
|
||||
: { value: mime.lookup(type), params: {} };
|
||||
};
|
||||
|
||||
@ -92,7 +94,7 @@ exports.normalizeType = function(type){
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.normalizeTypes = function(types){
|
||||
exports.normalizeTypes = function (types) {
|
||||
var ret = [];
|
||||
|
||||
for (var i = 0; i < types.length; ++i) {
|
||||
@ -111,8 +113,10 @@ exports.normalizeTypes = function(types){
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.contentDisposition = deprecate.function(contentDisposition,
|
||||
'utils.contentDisposition: use content-disposition npm module instead');
|
||||
exports.contentDisposition = deprecate.function(
|
||||
contentDisposition,
|
||||
'utils.contentDisposition: use content-disposition npm module instead'
|
||||
);
|
||||
|
||||
/**
|
||||
* Parse accept params `str` returning an
|
||||
@ -123,9 +127,9 @@ exports.contentDisposition = deprecate.function(contentDisposition,
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function acceptParams (str) {
|
||||
function acceptParams(str) {
|
||||
var parts = str.split(/ *; */);
|
||||
var ret = { value: parts[0], quality: 1, params: {} }
|
||||
var ret = { value: parts[0], quality: 1, params: {} };
|
||||
|
||||
for (var i = 1; i < parts.length; ++i) {
|
||||
var pms = parts[i].split(/ *= */);
|
||||
@ -147,7 +151,7 @@ function acceptParams (str) {
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.compileETag = function(val) {
|
||||
exports.compileETag = function (val) {
|
||||
var fn;
|
||||
|
||||
if (typeof val === 'function') {
|
||||
@ -169,7 +173,7 @@ exports.compileETag = function(val) {
|
||||
}
|
||||
|
||||
return fn;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Compile "query parser" value to function.
|
||||
@ -202,7 +206,7 @@ exports.compileQueryParser = function compileQueryParser(val) {
|
||||
}
|
||||
|
||||
return fn;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Compile "proxy trust" value to function.
|
||||
@ -212,27 +216,32 @@ exports.compileQueryParser = function compileQueryParser(val) {
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.compileTrust = function(val) {
|
||||
exports.compileTrust = function (val) {
|
||||
if (typeof val === 'function') return val;
|
||||
|
||||
if (val === true) {
|
||||
// Support plain true/false
|
||||
return function(){ return true };
|
||||
return function () {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof val === 'number') {
|
||||
// Support trusting hop count
|
||||
return function(a, i){ return i < val };
|
||||
return function (a, i) {
|
||||
return i < val;
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof val === 'string') {
|
||||
// Support comma-separated values
|
||||
val = val.split(',')
|
||||
.map(function (v) { return v.trim() })
|
||||
val = val.split(',').map(function (v) {
|
||||
return v.trim();
|
||||
});
|
||||
}
|
||||
|
||||
return proxyaddr.compile(val || []);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the charset in a given Content-Type string.
|
||||
@ -267,14 +276,12 @@ exports.setCharset = function setCharset(type, charset) {
|
||||
* @private
|
||||
*/
|
||||
|
||||
function createETagGenerator (options) {
|
||||
return function generateETag (body, encoding) {
|
||||
var buf = !Buffer.isBuffer(body)
|
||||
? Buffer.from(body, encoding)
|
||||
: body
|
||||
function createETagGenerator(options) {
|
||||
return function generateETag(body, encoding) {
|
||||
var buf = !Buffer.isBuffer(body) ? Buffer.from(body, encoding) : body;
|
||||
|
||||
return etag(buf, options)
|
||||
}
|
||||
return etag(buf, options);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -287,7 +294,7 @@ function createETagGenerator (options) {
|
||||
|
||||
function parseExtendedQueryString(str) {
|
||||
return qs.parse(str, {
|
||||
allowPrototypes: true
|
||||
allowPrototypes: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
19
node_modules/express/lib/view.js
generated
vendored
19
node_modules/express/lib/view.js
generated
vendored
@ -58,15 +58,18 @@ function View(name, options) {
|
||||
this.root = opts.root;
|
||||
|
||||
if (!this.ext && !this.defaultEngine) {
|
||||
throw new Error('No default engine was specified and no extension was provided.');
|
||||
throw new Error(
|
||||
'No default engine was specified and no extension was provided.'
|
||||
);
|
||||
}
|
||||
|
||||
var fileName = name;
|
||||
|
||||
if (!this.ext) {
|
||||
// get extension from default engine name
|
||||
this.ext = this.defaultEngine[0] !== '.'
|
||||
? '.' + this.defaultEngine
|
||||
this.ext =
|
||||
this.defaultEngine[0] !== '.' ?
|
||||
'.' + this.defaultEngine
|
||||
: this.defaultEngine;
|
||||
|
||||
fileName += this.ext;
|
||||
@ -74,17 +77,17 @@ function View(name, options) {
|
||||
|
||||
if (!opts.engines[this.ext]) {
|
||||
// load engine
|
||||
var mod = this.ext.slice(1)
|
||||
debug('require "%s"', mod)
|
||||
var mod = this.ext.slice(1);
|
||||
debug('require "%s"', mod);
|
||||
|
||||
// default engine export
|
||||
var fn = require(mod).__express
|
||||
var fn = require(mod).__express;
|
||||
|
||||
if (typeof fn !== 'function') {
|
||||
throw new Error('Module "' + mod + '" does not provide a view engine.')
|
||||
throw new Error('Module "' + mod + '" does not provide a view engine.');
|
||||
}
|
||||
|
||||
opts.engines[this.ext] = fn
|
||||
opts.engines[this.ext] = fn;
|
||||
}
|
||||
|
||||
// store loaded engine
|
||||
|
Reference in New Issue
Block a user