Initial import from local backup (Documents-Playground/pakerpale)
This commit is contained in:
36
node_modules/express-http-proxy/lib/as.js
generated
vendored
Normal file
36
node_modules/express-http-proxy/lib/as.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
* Trivial convenience methods for parsing Buffers
|
||||
*/
|
||||
|
||||
function asBuffer(body, options) {
|
||||
|
||||
var ret;
|
||||
if (Buffer.isBuffer(body)) {
|
||||
ret = body;
|
||||
} else if (typeof body === 'object') {
|
||||
ret = new Buffer(JSON.stringify(body), options.reqBodyEncoding);
|
||||
} else if (typeof body === 'string') {
|
||||
ret = new Buffer(body, options.reqBodyEncodeing);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function asBufferOrString(body) {
|
||||
|
||||
var ret;
|
||||
if (Buffer.isBuffer(body)) {
|
||||
ret = body;
|
||||
} else if (typeof body === 'object') {
|
||||
ret = JSON.stringify(body);
|
||||
} else if (typeof body === 'string') {
|
||||
ret = body;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buffer: asBuffer,
|
||||
bufferOrString: asBufferOrString
|
||||
};
|
||||
9
node_modules/express-http-proxy/lib/chunkLength.js
generated
vendored
Normal file
9
node_modules/express-http-proxy/lib/chunkLength.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
function chunkLength(chunks) {
|
||||
return chunks.reduce(function (len, buf) {
|
||||
return len + buf.length;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
module.exports = chunkLength;
|
||||
5
node_modules/express-http-proxy/lib/isUnset.js
generated
vendored
Normal file
5
node_modules/express-http-proxy/lib/isUnset.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (val) {
|
||||
return (typeof val === 'undefined' || val === '' || val === null);
|
||||
};
|
||||
10
node_modules/express-http-proxy/lib/mockHTTP.js
generated
vendored
Normal file
10
node_modules/express-http-proxy/lib/mockHTTP.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
var app = require('express')();
|
||||
|
||||
app.use('/status/:status', function (req, res) {
|
||||
res.status(Number(req.params.status));
|
||||
res.send();
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
113
node_modules/express-http-proxy/lib/requestOptions.js
generated
vendored
Normal file
113
node_modules/express-http-proxy/lib/requestOptions.js
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
'use strict';
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
var url = require('url');
|
||||
var getRawBody = require('raw-body');
|
||||
var isUnset = require('./isUnset');
|
||||
|
||||
function extend(obj, source, skips) {
|
||||
|
||||
if (!source) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
for (var prop in source) {
|
||||
if (!skips || skips.indexOf(prop) === -1) {
|
||||
obj[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
function parseHost(Container) {
|
||||
var host = Container.params.host;
|
||||
var req = Container.user.req;
|
||||
var options = Container.options;
|
||||
host = (typeof host === 'function') ? host(req) : host.toString();
|
||||
|
||||
if (!host) {
|
||||
return new Error('Empty host parameter');
|
||||
}
|
||||
|
||||
if (!/http(s)?:\/\//.test(host)) {
|
||||
host = 'http://' + host;
|
||||
}
|
||||
|
||||
var parsed = url.parse(host);
|
||||
|
||||
if (!parsed.hostname) {
|
||||
return new Error('Unable to parse hostname, possibly missing protocol://?');
|
||||
}
|
||||
|
||||
var ishttps = options.https || parsed.protocol === 'https:';
|
||||
|
||||
return {
|
||||
host: parsed.hostname,
|
||||
port: parsed.port || (ishttps ? 443 : 80),
|
||||
module: ishttps ? https : http,
|
||||
};
|
||||
}
|
||||
|
||||
function reqHeaders(req, options) {
|
||||
|
||||
|
||||
var headers = options.headers || {};
|
||||
|
||||
var skipHdrs = [ 'connection', 'content-length' ];
|
||||
if (!options.preserveHostHdr) {
|
||||
skipHdrs.push('host');
|
||||
}
|
||||
var hds = extend(headers, req.headers, skipHdrs);
|
||||
hds.connection = 'close';
|
||||
|
||||
return hds;
|
||||
}
|
||||
|
||||
function createRequestOptions(req, res, options) {
|
||||
|
||||
// prepare proxyRequest
|
||||
|
||||
var reqOpt = {
|
||||
headers: reqHeaders(req, options),
|
||||
method: req.method,
|
||||
path: req.path,
|
||||
params: req.params,
|
||||
};
|
||||
|
||||
if (options.preserveReqSession) {
|
||||
reqOpt.session = req.session;
|
||||
}
|
||||
|
||||
return Promise.resolve(reqOpt);
|
||||
}
|
||||
|
||||
// extract to bodyContent object
|
||||
|
||||
function bodyContent(req, res, options) {
|
||||
var parseReqBody = isUnset(options.parseReqBody) ? true : options.parseReqBody;
|
||||
|
||||
function maybeParseBody(req, limit) {
|
||||
if (req.body) {
|
||||
return Promise.resolve(req.body);
|
||||
} else {
|
||||
// Returns a promise if no callback specified and global Promise exists.
|
||||
|
||||
return getRawBody(req, {
|
||||
length: req.headers['content-length'],
|
||||
limit: limit,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (parseReqBody) {
|
||||
return maybeParseBody(req, options.limit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
create: createRequestOptions,
|
||||
bodyContent: bodyContent,
|
||||
parseHost: parseHost
|
||||
};
|
||||
79
node_modules/express-http-proxy/lib/resolveOptions.js
generated
vendored
Normal file
79
node_modules/express-http-proxy/lib/resolveOptions.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
'use strict';
|
||||
|
||||
var debug = require('debug')('express-http-proxy');
|
||||
|
||||
var isUnset = require('../lib/isUnset');
|
||||
|
||||
function resolveBodyEncoding(reqBodyEncoding) {
|
||||
|
||||
/* For reqBodyEncoding, these is a meaningful difference between null and
|
||||
* undefined. null should be passed forward as the value of reqBodyEncoding,
|
||||
* and undefined should result in utf-8.
|
||||
*/
|
||||
return reqBodyEncoding !== undefined ? reqBodyEncoding : 'utf-8';
|
||||
}
|
||||
|
||||
// parse client arguments
|
||||
|
||||
function resolveOptions(options) {
|
||||
options = options || {};
|
||||
var resolved;
|
||||
|
||||
if (options.decorateRequest) {
|
||||
throw new Error(
|
||||
'decorateRequest is REMOVED; use proxyReqOptDecorator and' +
|
||||
'proxyReqBodyDecorator instead. see README.md'
|
||||
);
|
||||
}
|
||||
|
||||
if (options.forwardPath || options.forwardPathAsync) {
|
||||
console.warn(
|
||||
'forwardPath and forwardPathAsync are DEPRECATED' +
|
||||
'and should be replaced with proxyReqPathResolver'
|
||||
);
|
||||
}
|
||||
|
||||
if (options.intercept) {
|
||||
console.warn(
|
||||
'DEPRECATED: intercept. Use decorateUseRes instead.' +
|
||||
' Please see README for more information.'
|
||||
);
|
||||
}
|
||||
|
||||
resolved = {
|
||||
limit: options.limit || '1mb',
|
||||
proxyReqPathResolver: options.proxyReqPathResolver
|
||||
|| options.forwardPathAsync
|
||||
|| options.forwardPath,
|
||||
proxyReqOptDecorator: options.proxyReqOptDecorator,
|
||||
proxyReqBodyDecorator: options.proxyReqBodyDecorator,
|
||||
userResDecorator: options.userResDecorator || options.intercept,
|
||||
userResHeaderDecorator: options.userResHeaderDecorator,
|
||||
proxyErrorHandler: options.proxyErrorHandler,
|
||||
filter: options.filter,
|
||||
// For backwards compatability, we default to legacy behavior for newly added settings.
|
||||
|
||||
parseReqBody: isUnset(options.parseReqBody) ? true : options.parseReqBody,
|
||||
preserveHostHdr: options.preserveHostHdr,
|
||||
memoizeHost: isUnset(options.memoizeHost) ? true : options.memoizeHost,
|
||||
reqBodyEncoding: resolveBodyEncoding(options.reqBodyEncoding),
|
||||
skipToNextHandlerFilter: options.skipToNextHandlerFilter,
|
||||
headers: options.headers,
|
||||
preserveReqSession: options.preserveReqSession,
|
||||
https: options.https,
|
||||
port: options.port,
|
||||
reqAsBuffer: options.reqAsBuffer,
|
||||
timeout: options.timeout
|
||||
};
|
||||
|
||||
// automatically opt into stream mode if no response modifiers are specified
|
||||
|
||||
resolved.stream = !resolved.skipToNextHandlerFilter &&
|
||||
!resolved.userResDecorator &&
|
||||
!resolved.userResHeaderDecorator;
|
||||
|
||||
debug(resolved);
|
||||
return resolved;
|
||||
}
|
||||
|
||||
module.exports = resolveOptions;
|
||||
35
node_modules/express-http-proxy/lib/scopeContainer.js
generated
vendored
Normal file
35
node_modules/express-http-proxy/lib/scopeContainer.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
var resolveOptions = require('../lib/resolveOptions');
|
||||
|
||||
// The Container object is passed down the chain of Promises, with each one
|
||||
// of them mutating and returning Container. The goal is that (eventually)
|
||||
// author using this library // could hook into/override any of these
|
||||
// workflow steps with a Promise or simple function.
|
||||
// Container for scoped arguments in a promise chain. Each promise recieves
|
||||
// this as its argument, and returns it.
|
||||
//
|
||||
// Do not expose the details of this to hooks/user functions.
|
||||
|
||||
function Container(req, res, next, host, userOptions) {
|
||||
return {
|
||||
user: {
|
||||
req: req,
|
||||
res: res,
|
||||
next: next,
|
||||
},
|
||||
proxy: {
|
||||
req: undefined,
|
||||
res: undefined,
|
||||
resData: undefined, // from proxy res
|
||||
bodyContent: undefined, // for proxy req
|
||||
reqBuilder: {}, // reqOpt, intended as first arg to http(s)?.request
|
||||
},
|
||||
options: resolveOptions(userOptions),
|
||||
params: {
|
||||
host: host,
|
||||
userOptions: userOptions
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = Container;
|
||||
Reference in New Issue
Block a user