This commit is contained in:
2022-09-30 05:39:11 +00:00
parent 41ee9463ae
commit 4687fa49bc
11418 changed files with 1312504 additions and 0 deletions

3
buildfiles/node_modules/global-agent/.flowconfig generated vendored Normal file
View File

@ -0,0 +1,3 @@
[ignore]
.*/node_modules/.*/test/.*
<PROJECT_ROOT>/dist/.*

24
buildfiles/node_modules/global-agent/LICENSE generated vendored Normal file
View File

@ -0,0 +1,24 @@
Copyright (c) 2019, Gajus Kuizinas (http://gajus.com/)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Gajus Kuizinas (http://gajus.com/) nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ANUARY BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

239
buildfiles/node_modules/global-agent/README.md generated vendored Normal file
View File

@ -0,0 +1,239 @@
# global-agent
[![GitSpo Mentions](https://gitspo.com/badges/mentions/gajus/global-agent?style=flat-square)](https://gitspo.com/mentions/gajus/global-agent)
[![Travis build status](http://img.shields.io/travis/gajus/global-agent/master.svg?style=flat-square)](https://travis-ci.org/gajus/global-agent)
[![Coveralls](https://img.shields.io/coveralls/gajus/global-agent.svg?style=flat-square)](https://coveralls.io/github/gajus/global-agent)
[![NPM version](http://img.shields.io/npm/v/global-agent.svg?style=flat-square)](https://www.npmjs.org/package/global-agent)
[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social&label=Follow)](https://twitter.com/kuizinas)
Global HTTP/HTTPS proxy configurable using environment variables.
* [Usage](#usage)
* [Setup proxy using `global-agent/bootstrap`](#setup-proxy-using-global-agentbootstrap)
* [Setup proxy using `bootstrap` routine](#setup-proxy-using-bootstrap-routine)
* [Runtime configuration](#runtime-configuration)
* [Exclude URLs](#exclude-urls)
* [Enable logging](#enable-logging)
* [API](#api)
* [`createGlobalProxyAgent`](#createglobalproxyagent)
* [Environment variables](#environment-variables)
* [`global.GLOBAL_AGENT`](#globalglobal_agent)
* [Supported libraries](#supported-libraries)
* [FAQ](#faq)
* [What is the reason `global-agent` overrides explicitly configured HTTP(S) agent?](#what-is-the-reason-global-agent-overrides-explicitly-configured-https-agent)
* [What is the reason `global-agent/bootstrap` does not use `HTTP_PROXY`?](#what-is-the-reason-global-agentbootstrap-does-not-use-http_proxy)
* [What is the difference from `global-tunnel` and `tunnel`?](#what-is-the-difference-from-global-tunnel-and-tunnel)
## Usage
### Setup proxy using `global-agent/bootstrap`
To configure HTTP proxy:
1. Import `global-agent/bootstrap`.
1. Export HTTP proxy address as `GLOBAL_AGENT_HTTP_PROXY` environment variable.
Code:
```js
import 'global-agent/bootstrap';
// or:
// import {bootstrap} from 'global-agent';
// bootstrap();
```
Bash:
```bash
$ export GLOBAL_AGENT_HTTP_PROXY=http://127.0.0.1:8080
```
Alternatively, you can preload module using Node.js `--require, -r` configuration, e.g.
```bash
$ export GLOBAL_AGENT_HTTP_PROXY=http://127.0.0.1:8080
$ node -r 'global-agent/bootstrap' your-script.js
```
### Setup proxy using `bootstrap` routine
Instead of importing a self-initialising script with side-effects as demonstrated in the [setup proxy using `global-agent/bootstrap`](#setup-proxy-using-global-agentbootstrap) documentation, you can import `bootstrap` routine and explicitly evaluate the bootstrap logic, e.g.
```js
import {
bootstrap
} from 'global-agent';
bootstrap();
```
This is useful if you need to conditionally bootstrap `global-agent`, e.g.
```js
import {
bootstrap
} from 'global-agent';
import globalTunner from 'global-tunnel-ng';
const MAJOR_NODEJS_VERSION = parseInt(process.version.slice(1).split('.')[0], 10);
if (MAJOR_NODEJS_VERSION >= 10) {
// `global-agent` works with Node.js v10 and above.
bootstrap();
} else {
// `global-tunnel-ng` works only with Node.js v10 and below.
globalTunnel.initialize();
}
```
### Setup proxy using `createGlobalProxyAgent`
If you do not want to use `global.GLOBAL_AGENT` variable, then you can use `createGlobalProxyAgent` to instantiate a controlled instance of `global-agent`, e.g.
```js
import {
createGlobalProxyAgent
} from 'global-agent';
const globalProxyAgent = createGlobalProxyAgent();
```
Unlike `bootstrap` routine, `createGlobalProxyAgent` factory does not create `global.GLOBAL_AGENT` variable and does not guard against multiple initializations of `global-agent`. The result object of `createGlobalProxyAgent` is equivalent to `global.GLOBAL_AGENT`.
### Runtime configuration
`global-agent/bootstrap` script copies `process.env.GLOBAL_AGENT_HTTP_PROXY` value to `global.GLOBAL_AGENT.HTTP_PROXY` and continues to use the latter variable.
You can override the `global.GLOBAL_AGENT.HTTP_PROXY` value at runtime to change proxy behaviour, e.g.
```js
http.get('http://127.0.0.1:8000');
global.GLOBAL_AGENT.HTTP_PROXY = 'http://127.0.0.1:8001';
http.get('http://127.0.0.1:8000');
global.GLOBAL_AGENT.HTTP_PROXY = 'http://127.0.0.1:8002';
```
The first HTTP request is going to use http://127.0.0.1:8001 proxy and the secord request is going to use http://127.0.0.1:8002.
All `global-agent` configuration is available under `global.GLOBAL_AGENT` namespace.
### Exclude URLs
The `GLOBAL_AGENT_NO_PROXY` environment variable specifies a pattern of URLs that should be excluded from proxying. `GLOBAL_AGENT_NO_PROXY` value is a comma-separated list of domain names. Asterisks can be used as wildcards, e.g.
```bash
export GLOBAL_AGENT_NO_PROXY='*.foo.com,baz.com'
```
says to contact all machines with the 'foo.com' TLD and 'baz.com' domains directly.
### Separate proxy for HTTPS
The environment variable `GLOBAL_AGENT_HTTPS_PROXY` can be set to specify a separate proxy for HTTPS requests. When this variable is not set `GLOBAL_AGENT_HTTP_PROXY` is used for both HTTP and HTTPS requests.
### Enable logging
`global-agent` is using [`roarr`](https://www.npmjs.com/package/roarr) logger to log HTTP requests and response (HTTP status code and headers), e.g.
```json
{"context":{"program":"global-agent","namespace":"Agent","logLevel":10,"destination":"http://gajus.com","proxy":"http://127.0.0.1:8076"},"message":"proxying request","sequence":1,"time":1556269669663,"version":"1.0.0"}
{"context":{"program":"global-agent","namespace":"Agent","logLevel":10,"headers":{"content-type":"text/plain","content-length":"2","date":"Fri, 26 Apr 2019 12:07:50 GMT","connection":"close"},"requestId":6,"statusCode":200},"message":"proxying response","sequence":2,"time":1557133856955,"version":"1.0.0"}
```
Export `ROARR_LOG=true` environment variable to enable log printing to stdout.
Use [`roarr-cli`](https://github.com/gajus/roarr-cli) program to pretty-print the logs.
## API
### `createGlobalProxyAgent`
```js
/**
* @property environmentVariableNamespace Defines namespace of `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables. (Default: `GLOBAL_AGENT_`)
* @property forceGlobalAgent Forces to use `global-agent` HTTP(S) agent even when request was explicitly constructed with another agent. (Default: `true`)
* @property socketConnectionTimeout Destroys socket if connection is not established within the timeout. (Default: `60000`)
*/
type ProxyAgentConfigurationInputType = {|
+environmentVariableNamespace?: string,
+forceGlobalAgent?: boolean,
+socketConnectionTimeout?: number,
|};
(configurationInput: ProxyAgentConfigurationInputType) => ProxyAgentConfigurationType;
```
### Environment variables
|Name|Description|Default|
|---|---|---|
|`GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE`|Defines namespace of `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables.|`GLOBAL_AGENT_`|
|`GLOBAL_AGENT_FORCE_GLOBAL_AGENT`|Forces to use `global-agent` HTTP(S) agent even when request was explicitly constructed with another agent.|`true`|
|`GLOBAL_AGENT_SOCKET_CONNECTION_TIMEOUT`|Destroys socket if connection is not established within the timeout.|`60000`|
|`${NAMESPACE}_HTTP_PROXY`|Sets the initial proxy controller HTTP_PROXY value.|N/A|
|`${NAMESPACE}_HTTPS_PROXY`|Sets the initial proxy controller HTTPS_PROXY value.|N/A|
|`${NAMESPACE}_NO_PROXY`|Sets the initial proxy controller NO_PROXY value.|N/A|
### `global.GLOBAL_AGENT`
`global.GLOBAL_AGENT` is initialized by `bootstrap` routine.
`global.GLOBAL_AGENT` has the following properties:
|Name|Description|Configurable|
|---|---|---|
|`HTTP_PROXY`|Yes|Sets HTTP proxy to use.|
|`HTTPS_PROXY`|Yes|Sets a distinct proxy to use for HTTPS requests.|
|`NO_PROXY`|Yes|Specifies a pattern of URLs that should be excluded from proxying. See [Exclude URLs](#exclude-urls).|
## Supported libraries
`global-agent` works with all libraries that internally use [`http.request`](https://nodejs.org/api/http.html#http_http_request_options_callback).
`global-agent` has been tested to work with:
* [`got`](https://www.npmjs.com/package/got)
* [`axios`](https://www.npmjs.com/package/axios)
* [`request`](https://www.npmjs.com/package/axios)
## FAQ
### What is the reason `global-agent` overrides explicitly configured HTTP(S) agent?
By default, `global-agent` overrides [`agent` property](https://nodejs.org/api/http.html#http_http_request_options_callback) of any HTTP request, even if `agent` property was explicitly set when constructing a HTTP request. This behaviour allows to intercept requests of libraries that use a custom instance of an agent per default (e.g. Stripe SDK [uses an `http(s).globalAgent` instance pre-configured with `keepAlive: true`](https://github.com/stripe/stripe-node/blob/e542902dd8fbe591fe3c3ce07a7e89d1d60e4cf7/lib/StripeResource.js#L11-L12)).
This behaviour can be disabled with `GLOBAL_AGENT_FORCE_GLOBAL_AGENT=false` environment variable. When disabled, then `global-agent` will only set `agent` property when it is not already defined or if `agent` is an instance of `http(s).globalAgent`.
### What is the reason `global-agent/bootstrap` does not use `HTTP_PROXY`?
Some libraries (e.g. [`request`](https://npmjs.org/package/request)) change their behaviour when `HTTP_PROXY` environment variable is present. Using a namespaced environment variable prevents conflicting library behaviour.
You can override this behaviour by configuring `GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE` variable, e.g.
```bash
$ export GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE=
```
Now script initialized using `global-agent/bootstrap` will use `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables.
### What is the difference from `global-tunnel` and `tunnel`?
[`global-tunnel`](https://github.com/salesforce/global-tunnel) (including [`global-tunnel-ng`](https://github.com/np-maintain/global-tunnel) and [`tunnel`](https://npmjs.com/package/tunnel)) are designed to support legacy Node.js versions. They use various [workarounds](https://github.com/koichik/node-tunnel/blob/5fb2fb424788597146b7be6729006cad1cf9e9a8/lib/tunnel.js#L134-L144) and rely on [monkey-patching `http.request`, `http.get`, `https.request` and `https.get` methods](https://github.com/np-maintain/global-tunnel/blob/51413dcf0534252b5049ec213105c7063ccc6367/index.js#L302-L338).
In contrast, `global-agent` supports Node.js v10 and above, and does not implements workarounds for the older Node.js versions.

1
buildfiles/node_modules/global-agent/bootstrap.js generated vendored Normal file
View File

@ -0,0 +1 @@
require('./dist/index').bootstrap();

18
buildfiles/node_modules/global-agent/dist/Logger.js generated vendored Normal file
View File

@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _roarr = _interopRequireDefault(require("roarr"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const Logger = _roarr.default.child({
package: 'global-agent'
});
var _default = Logger;
exports.default = _default;
//# sourceMappingURL=Logger.js.map

View File

@ -0,0 +1,10 @@
// @flow
import Roarr from 'roarr';
const Logger = Roarr
.child({
package: 'global-agent',
});
export default Logger;

View File

@ -0,0 +1 @@
{"version":3,"sources":["../src/Logger.js"],"names":["Logger","Roarr","child","package"],"mappings":";;;;;;;AAEA;;;;AAEA,MAAMA,MAAM,GAAGC,eACZC,KADY,CACN;AACLC,EAAAA,OAAO,EAAE;AADJ,CADM,CAAf;;eAKeH,M","sourcesContent":["// @flow\n\nimport Roarr from 'roarr';\n\nconst Logger = Roarr\n .child({\n package: 'global-agent',\n });\n\nexport default Logger;\n"],"file":"Logger.js"}

View File

@ -0,0 +1,174 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _serializeError = require("serialize-error");
var _boolean = require("boolean");
var _Logger = _interopRequireDefault(require("../Logger"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const log = _Logger.default.child({
namespace: 'Agent'
});
let requestId = 0;
class Agent {
constructor(isProxyConfigured, mustUrlUseProxy, getUrlProxy, fallbackAgent, socketConnectionTimeout) {
this.fallbackAgent = fallbackAgent;
this.isProxyConfigured = isProxyConfigured;
this.mustUrlUseProxy = mustUrlUseProxy;
this.getUrlProxy = getUrlProxy;
this.socketConnectionTimeout = socketConnectionTimeout;
}
addRequest(request, configuration) {
let requestUrl; // It is possible that addRequest was constructed for a proxied request already, e.g.
// "request" package does this when it detects that a proxy should be used
// https://github.com/request/request/blob/212570b6971a732b8dd9f3c73354bcdda158a737/request.js#L402
// https://gist.github.com/gajus/e2074cd3b747864ffeaabbd530d30218
if (request.path.startsWith('http://') || request.path.startsWith('https://')) {
requestUrl = request.path;
} else {
requestUrl = this.protocol + '//' + (configuration.hostname || configuration.host) + (configuration.port === 80 || configuration.port === 443 ? '' : ':' + configuration.port) + request.path;
}
if (!this.isProxyConfigured()) {
log.trace({
destination: requestUrl
}, 'not proxying request; GLOBAL_AGENT.HTTP_PROXY is not configured'); // $FlowFixMe It appears that Flow is missing the method description.
this.fallbackAgent.addRequest(request, configuration);
return;
}
if (!this.mustUrlUseProxy(requestUrl)) {
log.trace({
destination: requestUrl
}, 'not proxying request; url matches GLOBAL_AGENT.NO_PROXY'); // $FlowFixMe It appears that Flow is missing the method description.
this.fallbackAgent.addRequest(request, configuration);
return;
}
const currentRequestId = requestId++;
const proxy = this.getUrlProxy(requestUrl);
if (this.protocol === 'http:') {
request.path = requestUrl;
if (proxy.authorization) {
request.setHeader('proxy-authorization', 'Basic ' + Buffer.from(proxy.authorization).toString('base64'));
}
}
log.trace({
destination: requestUrl,
proxy: 'http://' + proxy.hostname + ':' + proxy.port,
requestId: currentRequestId
}, 'proxying request');
request.on('error', error => {
log.error({
error: (0, _serializeError.serializeError)(error)
}, 'request error');
});
request.once('response', response => {
log.trace({
headers: response.headers,
requestId: currentRequestId,
statusCode: response.statusCode
}, 'proxying response');
});
request.shouldKeepAlive = false;
const connectionConfiguration = {
host: configuration.hostname || configuration.host,
port: configuration.port || 80,
proxy,
tls: {}
}; // add optional tls options for https requests.
// @see https://nodejs.org/docs/latest-v12.x/api/https.html#https_https_request_url_options_callback :
// > The following additional options from tls.connect()
// > - https://nodejs.org/docs/latest-v12.x/api/tls.html#tls_tls_connect_options_callback -
// > are also accepted:
// > ca, cert, ciphers, clientCertEngine, crl, dhparam, ecdhCurve, honorCipherOrder,
// > key, passphrase, pfx, rejectUnauthorized, secureOptions, secureProtocol, servername, sessionIdContext.
if (this.protocol === 'https:') {
connectionConfiguration.tls = {
ca: configuration.ca,
cert: configuration.cert,
ciphers: configuration.ciphers,
clientCertEngine: configuration.clientCertEngine,
crl: configuration.crl,
dhparam: configuration.dhparam,
ecdhCurve: configuration.ecdhCurve,
honorCipherOrder: configuration.honorCipherOrder,
key: configuration.key,
passphrase: configuration.passphrase,
pfx: configuration.pfx,
rejectUnauthorized: configuration.rejectUnauthorized,
secureOptions: configuration.secureOptions,
secureProtocol: configuration.secureProtocol,
servername: configuration.servername || connectionConfiguration.host,
sessionIdContext: configuration.sessionIdContext
}; // This is not ideal because there is no way to override this setting using `tls` configuration if `NODE_TLS_REJECT_UNAUTHORIZED=0`.
// However, popular HTTP clients (such as https://github.com/sindresorhus/got) come with pre-configured value for `rejectUnauthorized`,
// which makes it impossible to override that value globally and respect `rejectUnauthorized` for specific requests only.
//
// eslint-disable-next-line no-process-env
if (typeof process.env.NODE_TLS_REJECT_UNAUTHORIZED === 'string' && (0, _boolean.boolean)(process.env.NODE_TLS_REJECT_UNAUTHORIZED) === false) {
connectionConfiguration.tls.rejectUnauthorized = false;
}
} // $FlowFixMe It appears that Flow is missing the method description.
this.createConnection(connectionConfiguration, (error, socket) => {
log.trace({
target: connectionConfiguration
}, 'connecting'); // @see https://github.com/nodejs/node/issues/5757#issuecomment-305969057
if (socket) {
socket.setTimeout(this.socketConnectionTimeout, () => {
socket.destroy();
});
socket.once('connect', () => {
log.trace({
target: connectionConfiguration
}, 'connected');
socket.setTimeout(0);
});
socket.once('secureConnect', () => {
log.trace({
target: connectionConfiguration
}, 'connected (secure)');
socket.setTimeout(0);
});
}
if (error) {
request.emit('error', error);
} else {
log.debug('created socket');
socket.on('error', socketError => {
log.error({
error: (0, _serializeError.serializeError)(socketError)
}, 'socket error');
});
request.onSocket(socket);
}
});
}
}
var _default = Agent;
exports.default = _default;
//# sourceMappingURL=Agent.js.map

View File

@ -0,0 +1,212 @@
// @flow
import {
serializeError,
} from 'serialize-error';
import {
boolean,
} from 'boolean';
import Logger from '../Logger';
import type {
AgentType,
GetUrlProxyMethodType,
IsProxyConfiguredMethodType,
MustUrlUseProxyMethodType,
ProtocolType,
} from '../types';
const log = Logger.child({
namespace: 'Agent',
});
let requestId = 0;
class Agent {
defaultPort: number;
protocol: ProtocolType;
fallbackAgent: AgentType;
isProxyConfigured: IsProxyConfiguredMethodType;
mustUrlUseProxy: MustUrlUseProxyMethodType;
getUrlProxy: GetUrlProxyMethodType;
socketConnectionTimeout: number;
constructor (
isProxyConfigured: IsProxyConfiguredMethodType,
mustUrlUseProxy: MustUrlUseProxyMethodType,
getUrlProxy: GetUrlProxyMethodType,
fallbackAgent: AgentType,
socketConnectionTimeout: number,
) {
this.fallbackAgent = fallbackAgent;
this.isProxyConfigured = isProxyConfigured;
this.mustUrlUseProxy = mustUrlUseProxy;
this.getUrlProxy = getUrlProxy;
this.socketConnectionTimeout = socketConnectionTimeout;
}
addRequest (request: *, configuration: *) {
let requestUrl;
// It is possible that addRequest was constructed for a proxied request already, e.g.
// "request" package does this when it detects that a proxy should be used
// https://github.com/request/request/blob/212570b6971a732b8dd9f3c73354bcdda158a737/request.js#L402
// https://gist.github.com/gajus/e2074cd3b747864ffeaabbd530d30218
if (request.path.startsWith('http://') || request.path.startsWith('https://')) {
requestUrl = request.path;
} else {
requestUrl = this.protocol + '//' + (configuration.hostname || configuration.host) + (configuration.port === 80 || configuration.port === 443 ? '' : ':' + configuration.port) + request.path;
}
if (!this.isProxyConfigured()) {
log.trace({
destination: requestUrl,
}, 'not proxying request; GLOBAL_AGENT.HTTP_PROXY is not configured');
// $FlowFixMe It appears that Flow is missing the method description.
this.fallbackAgent.addRequest(request, configuration);
return;
}
if (!this.mustUrlUseProxy(requestUrl)) {
log.trace({
destination: requestUrl,
}, 'not proxying request; url matches GLOBAL_AGENT.NO_PROXY');
// $FlowFixMe It appears that Flow is missing the method description.
this.fallbackAgent.addRequest(request, configuration);
return;
}
const currentRequestId = requestId++;
const proxy = this.getUrlProxy(requestUrl);
if (this.protocol === 'http:') {
request.path = requestUrl;
if (proxy.authorization) {
request.setHeader('proxy-authorization', 'Basic ' + Buffer.from(proxy.authorization).toString('base64'));
}
}
log.trace({
destination: requestUrl,
proxy: 'http://' + proxy.hostname + ':' + proxy.port,
requestId: currentRequestId,
}, 'proxying request');
request.on('error', (error) => {
log.error({
error: serializeError(error),
}, 'request error');
});
request.once('response', (response) => {
log.trace({
headers: response.headers,
requestId: currentRequestId,
statusCode: response.statusCode,
}, 'proxying response');
});
request.shouldKeepAlive = false;
const connectionConfiguration = {
host: configuration.hostname || configuration.host,
port: configuration.port || 80,
proxy,
tls: {},
};
// add optional tls options for https requests.
// @see https://nodejs.org/docs/latest-v12.x/api/https.html#https_https_request_url_options_callback :
// > The following additional options from tls.connect()
// > - https://nodejs.org/docs/latest-v12.x/api/tls.html#tls_tls_connect_options_callback -
// > are also accepted:
// > ca, cert, ciphers, clientCertEngine, crl, dhparam, ecdhCurve, honorCipherOrder,
// > key, passphrase, pfx, rejectUnauthorized, secureOptions, secureProtocol, servername, sessionIdContext.
if (this.protocol === 'https:') {
connectionConfiguration.tls = {
ca: configuration.ca,
cert: configuration.cert,
ciphers: configuration.ciphers,
clientCertEngine: configuration.clientCertEngine,
crl: configuration.crl,
dhparam: configuration.dhparam,
ecdhCurve: configuration.ecdhCurve,
honorCipherOrder: configuration.honorCipherOrder,
key: configuration.key,
passphrase: configuration.passphrase,
pfx: configuration.pfx,
rejectUnauthorized: configuration.rejectUnauthorized,
secureOptions: configuration.secureOptions,
secureProtocol: configuration.secureProtocol,
servername: configuration.servername || connectionConfiguration.host,
sessionIdContext: configuration.sessionIdContext,
};
// This is not ideal because there is no way to override this setting using `tls` configuration if `NODE_TLS_REJECT_UNAUTHORIZED=0`.
// However, popular HTTP clients (such as https://github.com/sindresorhus/got) come with pre-configured value for `rejectUnauthorized`,
// which makes it impossible to override that value globally and respect `rejectUnauthorized` for specific requests only.
//
// eslint-disable-next-line no-process-env
if (typeof process.env.NODE_TLS_REJECT_UNAUTHORIZED === 'string' && boolean(process.env.NODE_TLS_REJECT_UNAUTHORIZED) === false) {
connectionConfiguration.tls.rejectUnauthorized = false;
}
}
// $FlowFixMe It appears that Flow is missing the method description.
this.createConnection(connectionConfiguration, (error, socket) => {
log.trace({
target: connectionConfiguration,
}, 'connecting');
// @see https://github.com/nodejs/node/issues/5757#issuecomment-305969057
if (socket) {
socket.setTimeout(this.socketConnectionTimeout, () => {
socket.destroy();
});
socket.once('connect', () => {
log.trace({
target: connectionConfiguration,
}, 'connected');
socket.setTimeout(0);
});
socket.once('secureConnect', () => {
log.trace({
target: connectionConfiguration,
}, 'connected (secure)');
socket.setTimeout(0);
});
}
if (error) {
request.emit('error', error);
} else {
log.debug('created socket');
socket.on('error', (socketError) => {
log.error({
error: serializeError(socketError),
}, 'socket error');
});
request.onSocket(socket);
}
});
}
}
export default Agent;

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _net = _interopRequireDefault(require("net"));
var _Agent = _interopRequireDefault(require("./Agent"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class HttpProxyAgent extends _Agent.default {
// @see https://github.com/sindresorhus/eslint-plugin-unicorn/issues/169#issuecomment-486980290
// eslint-disable-next-line unicorn/prevent-abbreviations
constructor(...args) {
super(...args);
this.protocol = 'http:';
this.defaultPort = 80;
}
createConnection(configuration, callback) {
const socket = _net.default.connect(configuration.proxy.port, configuration.proxy.hostname);
callback(null, socket);
}
}
var _default = HttpProxyAgent;
exports.default = _default;
//# sourceMappingURL=HttpProxyAgent.js.map

View File

@ -0,0 +1,30 @@
// @flow
import net from 'net';
import type {
ConnectionCallbackType,
ConnectionConfigurationType,
} from '../types';
import Agent from './Agent';
class HttpProxyAgent extends Agent {
// @see https://github.com/sindresorhus/eslint-plugin-unicorn/issues/169#issuecomment-486980290
// eslint-disable-next-line unicorn/prevent-abbreviations
constructor (...args: *) {
super(...args);
this.protocol = 'http:';
this.defaultPort = 80;
}
createConnection (configuration: ConnectionConfigurationType, callback: ConnectionCallbackType) {
const socket = net.connect(
configuration.proxy.port,
configuration.proxy.hostname,
);
callback(null, socket);
}
}
export default HttpProxyAgent;

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/classes/HttpProxyAgent.js"],"names":["HttpProxyAgent","Agent","constructor","args","protocol","defaultPort","createConnection","configuration","callback","socket","net","connect","proxy","port","hostname"],"mappings":";;;;;;;AAEA;;AAKA;;;;AAEA,MAAMA,cAAN,SAA6BC,cAA7B,CAAmC;AACjC;AACA;AACAC,EAAAA,WAAW,CAAE,GAAGC,IAAL,EAAc;AACvB,UAAM,GAAGA,IAAT;AAEA,SAAKC,QAAL,GAAgB,OAAhB;AACA,SAAKC,WAAL,GAAmB,EAAnB;AACD;;AAEDC,EAAAA,gBAAgB,CAAEC,aAAF,EAA8CC,QAA9C,EAAgF;AAC9F,UAAMC,MAAM,GAAGC,aAAIC,OAAJ,CACbJ,aAAa,CAACK,KAAd,CAAoBC,IADP,EAEbN,aAAa,CAACK,KAAd,CAAoBE,QAFP,CAAf;;AAKAN,IAAAA,QAAQ,CAAC,IAAD,EAAOC,MAAP,CAAR;AACD;;AAjBgC;;eAoBpBT,c","sourcesContent":["// @flow\n\nimport net from 'net';\nimport type {\n ConnectionCallbackType,\n ConnectionConfigurationType,\n} from '../types';\nimport Agent from './Agent';\n\nclass HttpProxyAgent extends Agent {\n // @see https://github.com/sindresorhus/eslint-plugin-unicorn/issues/169#issuecomment-486980290\n // eslint-disable-next-line unicorn/prevent-abbreviations\n constructor (...args: *) {\n super(...args);\n\n this.protocol = 'http:';\n this.defaultPort = 80;\n }\n\n createConnection (configuration: ConnectionConfigurationType, callback: ConnectionCallbackType) {\n const socket = net.connect(\n configuration.proxy.port,\n configuration.proxy.hostname,\n );\n\n callback(null, socket);\n }\n}\n\nexport default HttpProxyAgent;\n"],"file":"HttpProxyAgent.js"}

View File

@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _net = _interopRequireDefault(require("net"));
var _tls = _interopRequireDefault(require("tls"));
var _Agent = _interopRequireDefault(require("./Agent"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class HttpsProxyAgent extends _Agent.default {
// eslint-disable-next-line unicorn/prevent-abbreviations
constructor(...args) {
super(...args);
this.protocol = 'https:';
this.defaultPort = 443;
}
createConnection(configuration, callback) {
const socket = _net.default.connect(configuration.proxy.port, configuration.proxy.hostname);
socket.on('error', error => {
callback(error);
});
socket.once('data', () => {
const secureSocket = _tls.default.connect({ ...configuration.tls,
socket
});
callback(null, secureSocket);
});
let connectMessage = '';
connectMessage += 'CONNECT ' + configuration.host + ':' + configuration.port + ' HTTP/1.1\r\n';
connectMessage += 'Host: ' + configuration.host + ':' + configuration.port + '\r\n';
if (configuration.proxy.authorization) {
connectMessage += 'Proxy-Authorization: Basic ' + Buffer.from(configuration.proxy.authorization).toString('base64') + '\r\n';
}
connectMessage += '\r\n';
socket.write(connectMessage);
}
}
var _default = HttpsProxyAgent;
exports.default = _default;
//# sourceMappingURL=HttpsProxyAgent.js.map

View File

@ -0,0 +1,54 @@
// @flow
import net from 'net';
import tls from 'tls';
import type {
ConnectionCallbackType,
ConnectionConfigurationType,
} from '../types';
import Agent from './Agent';
class HttpsProxyAgent extends Agent {
// eslint-disable-next-line unicorn/prevent-abbreviations
constructor (...args: *) {
super(...args);
this.protocol = 'https:';
this.defaultPort = 443;
}
createConnection (configuration: ConnectionConfigurationType, callback: ConnectionCallbackType) {
const socket = net.connect(
configuration.proxy.port,
configuration.proxy.hostname,
);
socket.on('error', (error) => {
callback(error);
});
socket.once('data', () => {
const secureSocket = tls.connect({
...configuration.tls,
socket,
});
callback(null, secureSocket);
});
let connectMessage = '';
connectMessage += 'CONNECT ' + configuration.host + ':' + configuration.port + ' HTTP/1.1\r\n';
connectMessage += 'Host: ' + configuration.host + ':' + configuration.port + '\r\n';
if (configuration.proxy.authorization) {
connectMessage += 'Proxy-Authorization: Basic ' + Buffer.from(configuration.proxy.authorization).toString('base64') + '\r\n';
}
connectMessage += '\r\n';
socket.write(connectMessage);
}
}
export default HttpsProxyAgent;

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/classes/HttpsProxyAgent.js"],"names":["HttpsProxyAgent","Agent","constructor","args","protocol","defaultPort","createConnection","configuration","callback","socket","net","connect","proxy","port","hostname","on","error","once","secureSocket","tls","connectMessage","host","authorization","Buffer","from","toString","write"],"mappings":";;;;;;;AAEA;;AACA;;AAKA;;;;AAEA,MAAMA,eAAN,SAA8BC,cAA9B,CAAoC;AAClC;AACAC,EAAAA,WAAW,CAAE,GAAGC,IAAL,EAAc;AACvB,UAAM,GAAGA,IAAT;AAEA,SAAKC,QAAL,GAAgB,QAAhB;AACA,SAAKC,WAAL,GAAmB,GAAnB;AACD;;AAEDC,EAAAA,gBAAgB,CAAEC,aAAF,EAA8CC,QAA9C,EAAgF;AAC9F,UAAMC,MAAM,GAAGC,aAAIC,OAAJ,CACbJ,aAAa,CAACK,KAAd,CAAoBC,IADP,EAEbN,aAAa,CAACK,KAAd,CAAoBE,QAFP,CAAf;;AAKAL,IAAAA,MAAM,CAACM,EAAP,CAAU,OAAV,EAAoBC,KAAD,IAAW;AAC5BR,MAAAA,QAAQ,CAACQ,KAAD,CAAR;AACD,KAFD;AAIAP,IAAAA,MAAM,CAACQ,IAAP,CAAY,MAAZ,EAAoB,MAAM;AACxB,YAAMC,YAAY,GAAGC,aAAIR,OAAJ,CAAY,EAC/B,GAAGJ,aAAa,CAACY,GADc;AAE/BV,QAAAA;AAF+B,OAAZ,CAArB;;AAKAD,MAAAA,QAAQ,CAAC,IAAD,EAAOU,YAAP,CAAR;AACD,KAPD;AASA,QAAIE,cAAc,GAAG,EAArB;AAEAA,IAAAA,cAAc,IAAI,aAAab,aAAa,CAACc,IAA3B,GAAkC,GAAlC,GAAwCd,aAAa,CAACM,IAAtD,GAA6D,eAA/E;AACAO,IAAAA,cAAc,IAAI,WAAWb,aAAa,CAACc,IAAzB,GAAgC,GAAhC,GAAsCd,aAAa,CAACM,IAApD,GAA2D,MAA7E;;AAEA,QAAIN,aAAa,CAACK,KAAd,CAAoBU,aAAxB,EAAuC;AACrCF,MAAAA,cAAc,IAAI,gCAAgCG,MAAM,CAACC,IAAP,CAAYjB,aAAa,CAACK,KAAd,CAAoBU,aAAhC,EAA+CG,QAA/C,CAAwD,QAAxD,CAAhC,GAAoG,MAAtH;AACD;;AAEDL,IAAAA,cAAc,IAAI,MAAlB;AAEAX,IAAAA,MAAM,CAACiB,KAAP,CAAaN,cAAb;AACD;;AAxCiC;;eA2CrBpB,e","sourcesContent":["// @flow\n\nimport net from 'net';\nimport tls from 'tls';\nimport type {\n ConnectionCallbackType,\n ConnectionConfigurationType,\n} from '../types';\nimport Agent from './Agent';\n\nclass HttpsProxyAgent extends Agent {\n // eslint-disable-next-line unicorn/prevent-abbreviations\n constructor (...args: *) {\n super(...args);\n\n this.protocol = 'https:';\n this.defaultPort = 443;\n }\n\n createConnection (configuration: ConnectionConfigurationType, callback: ConnectionCallbackType) {\n const socket = net.connect(\n configuration.proxy.port,\n configuration.proxy.hostname,\n );\n\n socket.on('error', (error) => {\n callback(error);\n });\n\n socket.once('data', () => {\n const secureSocket = tls.connect({\n ...configuration.tls,\n socket,\n });\n\n callback(null, secureSocket);\n });\n\n let connectMessage = '';\n\n connectMessage += 'CONNECT ' + configuration.host + ':' + configuration.port + ' HTTP/1.1\\r\\n';\n connectMessage += 'Host: ' + configuration.host + ':' + configuration.port + '\\r\\n';\n\n if (configuration.proxy.authorization) {\n connectMessage += 'Proxy-Authorization: Basic ' + Buffer.from(configuration.proxy.authorization).toString('base64') + '\\r\\n';\n }\n\n connectMessage += '\\r\\n';\n\n socket.write(connectMessage);\n }\n}\n\nexport default HttpsProxyAgent;\n"],"file":"HttpsProxyAgent.js"}

View File

@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "Agent", {
enumerable: true,
get: function () {
return _Agent.default;
}
});
Object.defineProperty(exports, "HttpProxyAgent", {
enumerable: true,
get: function () {
return _HttpProxyAgent.default;
}
});
Object.defineProperty(exports, "HttpsProxyAgent", {
enumerable: true,
get: function () {
return _HttpsProxyAgent.default;
}
});
var _Agent = _interopRequireDefault(require("./Agent"));
var _HttpProxyAgent = _interopRequireDefault(require("./HttpProxyAgent"));
var _HttpsProxyAgent = _interopRequireDefault(require("./HttpsProxyAgent"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1,5 @@
// @flow
export {default as Agent} from './Agent';
export {default as HttpProxyAgent} from './HttpProxyAgent';
export {default as HttpsProxyAgent} from './HttpsProxyAgent';

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/classes/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAEA;;AACA;;AACA","sourcesContent":["// @flow\n\nexport {default as Agent} from './Agent';\nexport {default as HttpProxyAgent} from './HttpProxyAgent';\nexport {default as HttpsProxyAgent} from './HttpsProxyAgent';\n"],"file":"index.js"}

22
buildfiles/node_modules/global-agent/dist/errors.js generated vendored Normal file
View File

@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.UnexpectedStateError = void 0;
var _es6Error = _interopRequireDefault(require("es6-error"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint-disable fp/no-class, fp/no-this */
class UnexpectedStateError extends _es6Error.default {
constructor(message, code = 'UNEXPECTED_STATE_ERROR') {
super(message);
this.code = code;
}
}
exports.UnexpectedStateError = UnexpectedStateError;
//# sourceMappingURL=errors.js.map

View File

@ -0,0 +1,15 @@
// @flow
/* eslint-disable fp/no-class, fp/no-this */
import ExtendableError from 'es6-error';
export class UnexpectedStateError extends ExtendableError {
code: string;
constructor (message: string, code: string = 'UNEXPECTED_STATE_ERROR') {
super(message);
this.code = code;
}
}

View File

@ -0,0 +1 @@
{"version":3,"sources":["../src/errors.js"],"names":["UnexpectedStateError","ExtendableError","constructor","message","code"],"mappings":";;;;;;;AAIA;;;;AAFA;AAIO,MAAMA,oBAAN,SAAmCC,iBAAnC,CAAmD;AAGxDC,EAAAA,WAAW,CAAEC,OAAF,EAAmBC,IAAY,GAAG,wBAAlC,EAA4D;AACrE,UAAMD,OAAN;AAEA,SAAKC,IAAL,GAAYA,IAAZ;AACD;;AAPuD","sourcesContent":["// @flow\n\n/* eslint-disable fp/no-class, fp/no-this */\n\nimport ExtendableError from 'es6-error';\n\nexport class UnexpectedStateError extends ExtendableError {\n code: string;\n\n constructor (message: string, code: string = 'UNEXPECTED_STATE_ERROR') {\n super(message);\n\n this.code = code;\n }\n}\n"],"file":"errors.js"}

View File

@ -0,0 +1,175 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _http = _interopRequireDefault(require("http"));
var _https = _interopRequireDefault(require("https"));
var _boolean = require("boolean");
var _semver = _interopRequireDefault(require("semver"));
var _Logger = _interopRequireDefault(require("../Logger"));
var _classes = require("../classes");
var _errors = require("../errors");
var _utilities = require("../utilities");
var _createProxyController = _interopRequireDefault(require("./createProxyController"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const httpGet = _http.default.get;
const httpRequest = _http.default.request;
const httpsGet = _https.default.get;
const httpsRequest = _https.default.request;
const log = _Logger.default.child({
namespace: 'createGlobalProxyAgent'
});
const defaultConfigurationInput = {
environmentVariableNamespace: undefined,
forceGlobalAgent: undefined,
socketConnectionTimeout: 60000
};
const omitUndefined = subject => {
const keys = Object.keys(subject);
const result = {};
for (const key of keys) {
const value = subject[key];
if (value !== undefined) {
result[key] = value;
}
}
return result;
};
const createConfiguration = configurationInput => {
// eslint-disable-next-line no-process-env
const environment = process.env;
const defaultConfiguration = {
environmentVariableNamespace: typeof environment.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE === 'string' ? environment.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE : 'GLOBAL_AGENT_',
forceGlobalAgent: typeof environment.GLOBAL_AGENT_FORCE_GLOBAL_AGENT === 'string' ? (0, _boolean.boolean)(environment.GLOBAL_AGENT_FORCE_GLOBAL_AGENT) : true,
socketConnectionTimeout: typeof environment.GLOBAL_AGENT_SOCKET_CONNECTION_TIMEOUT === 'string' ? Number.parseInt(environment.GLOBAL_AGENT_SOCKET_CONNECTION_TIMEOUT, 10) : defaultConfigurationInput.socketConnectionTimeout
}; // $FlowFixMe
return { ...defaultConfiguration,
...omitUndefined(configurationInput)
};
};
const createGlobalProxyAgent = (configurationInput = defaultConfigurationInput) => {
const configuration = createConfiguration(configurationInput);
const proxyController = (0, _createProxyController.default)(); // eslint-disable-next-line no-process-env
proxyController.HTTP_PROXY = process.env[configuration.environmentVariableNamespace + 'HTTP_PROXY'] || null; // eslint-disable-next-line no-process-env
proxyController.HTTPS_PROXY = process.env[configuration.environmentVariableNamespace + 'HTTPS_PROXY'] || null; // eslint-disable-next-line no-process-env
proxyController.NO_PROXY = process.env[configuration.environmentVariableNamespace + 'NO_PROXY'] || null;
log.info({
configuration,
state: proxyController
}, 'global agent has been initialized');
const mustUrlUseProxy = getProxy => {
return url => {
if (!getProxy()) {
return false;
}
if (!proxyController.NO_PROXY) {
return true;
}
return !(0, _utilities.isUrlMatchingNoProxy)(url, proxyController.NO_PROXY);
};
};
const getUrlProxy = getProxy => {
return () => {
const proxy = getProxy();
if (!proxy) {
throw new _errors.UnexpectedStateError('HTTP(S) proxy must be configured.');
}
return (0, _utilities.parseProxyUrl)(proxy);
};
};
const getHttpProxy = () => {
return proxyController.HTTP_PROXY;
};
const BoundHttpProxyAgent = class extends _classes.HttpProxyAgent {
constructor() {
super(() => {
return getHttpProxy();
}, mustUrlUseProxy(getHttpProxy), getUrlProxy(getHttpProxy), _http.default.globalAgent, configuration.socketConnectionTimeout);
}
};
const httpAgent = new BoundHttpProxyAgent();
const getHttpsProxy = () => {
return proxyController.HTTPS_PROXY || proxyController.HTTP_PROXY;
};
const BoundHttpsProxyAgent = class extends _classes.HttpsProxyAgent {
constructor() {
super(() => {
return getHttpsProxy();
}, mustUrlUseProxy(getHttpsProxy), getUrlProxy(getHttpsProxy), _https.default.globalAgent, configuration.socketConnectionTimeout);
}
};
const httpsAgent = new BoundHttpsProxyAgent(); // Overriding globalAgent was added in v11.7.
// @see https://nodejs.org/uk/blog/release/v11.7.0/
if (_semver.default.gte(process.version, 'v11.7.0')) {
// @see https://github.com/facebook/flow/issues/7670
// $FlowFixMe
_http.default.globalAgent = httpAgent; // $FlowFixMe
_https.default.globalAgent = httpsAgent;
} // The reason this logic is used in addition to overriding http(s).globalAgent
// is because there is no guarantee that we set http(s).globalAgent variable
// before an instance of http(s).Agent has been already constructed by someone,
// e.g. Stripe SDK creates instances of http(s).Agent at the top-level.
// @see https://github.com/gajus/global-agent/pull/13
//
// We still want to override http(s).globalAgent when possible to enable logic
// in `bindHttpMethod`.
if (_semver.default.gte(process.version, 'v10.0.0')) {
// $FlowFixMe
_http.default.get = (0, _utilities.bindHttpMethod)(httpGet, httpAgent, configuration.forceGlobalAgent); // $FlowFixMe
_http.default.request = (0, _utilities.bindHttpMethod)(httpRequest, httpAgent, configuration.forceGlobalAgent); // $FlowFixMe
_https.default.get = (0, _utilities.bindHttpMethod)(httpsGet, httpsAgent, configuration.forceGlobalAgent); // $FlowFixMe
_https.default.request = (0, _utilities.bindHttpMethod)(httpsRequest, httpsAgent, configuration.forceGlobalAgent);
} else {
log.warn('attempt to initialize global-agent in unsupported Node.js version was ignored');
}
return proxyController;
};
var _default = createGlobalProxyAgent;
exports.default = _default;
//# sourceMappingURL=createGlobalProxyAgent.js.map

View File

@ -0,0 +1,197 @@
// @flow
import http from 'http';
import https from 'https';
import {
boolean as parseBoolean,
} from 'boolean';
import semver from 'semver';
import Logger from '../Logger';
import {
HttpProxyAgent,
HttpsProxyAgent,
} from '../classes';
import {
UnexpectedStateError,
} from '../errors';
import {
bindHttpMethod,
isUrlMatchingNoProxy,
parseProxyUrl,
} from '../utilities';
import type {
ProxyAgentConfigurationInputType,
ProxyAgentConfigurationType,
} from '../types';
import createProxyController from './createProxyController';
const httpGet = http.get;
const httpRequest = http.request;
const httpsGet = https.get;
const httpsRequest = https.request;
const log = Logger.child({
namespace: 'createGlobalProxyAgent',
});
const defaultConfigurationInput = {
environmentVariableNamespace: undefined,
forceGlobalAgent: undefined,
socketConnectionTimeout: 60000,
};
const omitUndefined = (subject) => {
const keys = Object.keys(subject);
const result = {};
for (const key of keys) {
const value = subject[key];
if (value !== undefined) {
result[key] = value;
}
}
return result;
};
const createConfiguration = (configurationInput: ProxyAgentConfigurationInputType): ProxyAgentConfigurationType => {
// eslint-disable-next-line no-process-env
const environment = process.env;
const defaultConfiguration = {
environmentVariableNamespace: typeof environment.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE === 'string' ? environment.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE : 'GLOBAL_AGENT_',
forceGlobalAgent: typeof environment.GLOBAL_AGENT_FORCE_GLOBAL_AGENT === 'string' ? parseBoolean(environment.GLOBAL_AGENT_FORCE_GLOBAL_AGENT) : true,
socketConnectionTimeout: typeof environment.GLOBAL_AGENT_SOCKET_CONNECTION_TIMEOUT === 'string' ? Number.parseInt(environment.GLOBAL_AGENT_SOCKET_CONNECTION_TIMEOUT, 10) : defaultConfigurationInput.socketConnectionTimeout,
};
// $FlowFixMe
return {
...defaultConfiguration,
...omitUndefined(configurationInput),
};
};
export default (configurationInput: ProxyAgentConfigurationInputType = defaultConfigurationInput) => {
const configuration = createConfiguration(configurationInput);
const proxyController = createProxyController();
// eslint-disable-next-line no-process-env
proxyController.HTTP_PROXY = process.env[configuration.environmentVariableNamespace + 'HTTP_PROXY'] || null;
// eslint-disable-next-line no-process-env
proxyController.HTTPS_PROXY = process.env[configuration.environmentVariableNamespace + 'HTTPS_PROXY'] || null;
// eslint-disable-next-line no-process-env
proxyController.NO_PROXY = process.env[configuration.environmentVariableNamespace + 'NO_PROXY'] || null;
log.info({
configuration,
state: proxyController,
}, 'global agent has been initialized');
const mustUrlUseProxy = (getProxy) => {
return (url) => {
if (!getProxy()) {
return false;
}
if (!proxyController.NO_PROXY) {
return true;
}
return !isUrlMatchingNoProxy(url, proxyController.NO_PROXY);
};
};
const getUrlProxy = (getProxy) => {
return () => {
const proxy = getProxy();
if (!proxy) {
throw new UnexpectedStateError('HTTP(S) proxy must be configured.');
}
return parseProxyUrl(proxy);
};
};
const getHttpProxy = () => {
return proxyController.HTTP_PROXY;
};
const BoundHttpProxyAgent = class extends HttpProxyAgent {
constructor () {
super(
() => {
return getHttpProxy();
},
mustUrlUseProxy(getHttpProxy),
getUrlProxy(getHttpProxy),
http.globalAgent,
configuration.socketConnectionTimeout,
);
}
};
const httpAgent = new BoundHttpProxyAgent();
const getHttpsProxy = () => {
return proxyController.HTTPS_PROXY || proxyController.HTTP_PROXY;
};
const BoundHttpsProxyAgent = class extends HttpsProxyAgent {
constructor () {
super(
() => {
return getHttpsProxy();
},
mustUrlUseProxy(getHttpsProxy),
getUrlProxy(getHttpsProxy),
https.globalAgent,
configuration.socketConnectionTimeout,
);
}
};
const httpsAgent = new BoundHttpsProxyAgent();
// Overriding globalAgent was added in v11.7.
// @see https://nodejs.org/uk/blog/release/v11.7.0/
if (semver.gte(process.version, 'v11.7.0')) {
// @see https://github.com/facebook/flow/issues/7670
// $FlowFixMe
http.globalAgent = httpAgent;
// $FlowFixMe
https.globalAgent = httpsAgent;
}
// The reason this logic is used in addition to overriding http(s).globalAgent
// is because there is no guarantee that we set http(s).globalAgent variable
// before an instance of http(s).Agent has been already constructed by someone,
// e.g. Stripe SDK creates instances of http(s).Agent at the top-level.
// @see https://github.com/gajus/global-agent/pull/13
//
// We still want to override http(s).globalAgent when possible to enable logic
// in `bindHttpMethod`.
if (semver.gte(process.version, 'v10.0.0')) {
// $FlowFixMe
http.get = bindHttpMethod(httpGet, httpAgent, configuration.forceGlobalAgent);
// $FlowFixMe
http.request = bindHttpMethod(httpRequest, httpAgent, configuration.forceGlobalAgent);
// $FlowFixMe
https.get = bindHttpMethod(httpsGet, httpsAgent, configuration.forceGlobalAgent);
// $FlowFixMe
https.request = bindHttpMethod(httpsRequest, httpsAgent, configuration.forceGlobalAgent);
} else {
log.warn('attempt to initialize global-agent in unsupported Node.js version was ignored');
}
return proxyController;
};

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,45 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _Logger = _interopRequireDefault(require("../Logger"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const log = _Logger.default.child({
namespace: 'createProxyController'
});
const KNOWN_PROPERTY_NAMES = ['HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY'];
const createProxyController = () => {
// eslint-disable-next-line fp/no-proxy
return new Proxy({
HTTP_PROXY: null,
HTTPS_PROXY: null,
NO_PROXY: null
}, {
set: (subject, name, value) => {
if (!KNOWN_PROPERTY_NAMES.includes(name)) {
throw new Error('Cannot set an unmapped property "' + name + '".');
}
subject[name] = value;
log.info({
change: {
name,
value
},
newConfiguration: subject
}, 'configuration changed');
return true;
}
});
};
var _default = createProxyController;
exports.default = _default;
//# sourceMappingURL=createProxyController.js.map

View File

@ -0,0 +1,46 @@
// @flow
import Logger from '../Logger';
type ProxyControllerType = {|
HTTP_PROXY: string | null,
HTTPS_PROXY: string | null,
NO_PROXY: string | null,
|};
const log = Logger.child({
namespace: 'createProxyController',
});
const KNOWN_PROPERTY_NAMES = [
'HTTP_PROXY',
'HTTPS_PROXY',
'NO_PROXY',
];
export default (): ProxyControllerType => {
// eslint-disable-next-line fp/no-proxy
return new Proxy({
HTTP_PROXY: null,
HTTPS_PROXY: null,
NO_PROXY: null,
}, {
set: (subject, name, value) => {
if (!KNOWN_PROPERTY_NAMES.includes(name)) {
throw new Error('Cannot set an unmapped property "' + name + '".');
}
subject[name] = value;
log.info({
change: {
name,
value,
},
newConfiguration: subject,
}, 'configuration changed');
return true;
},
});
};

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/factories/createProxyController.js"],"names":["log","Logger","child","namespace","KNOWN_PROPERTY_NAMES","Proxy","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","set","subject","name","value","includes","Error","info","change","newConfiguration"],"mappings":";;;;;;;AAEA;;;;AAQA,MAAMA,GAAG,GAAGC,gBAAOC,KAAP,CAAa;AACvBC,EAAAA,SAAS,EAAE;AADY,CAAb,CAAZ;;AAIA,MAAMC,oBAAoB,GAAG,CAC3B,YAD2B,EAE3B,aAF2B,EAG3B,UAH2B,CAA7B;;oCAM0C;AACxC;AACA,SAAO,IAAIC,KAAJ,CAAU;AACfC,IAAAA,UAAU,EAAE,IADG;AAEfC,IAAAA,WAAW,EAAE,IAFE;AAGfC,IAAAA,QAAQ,EAAE;AAHK,GAAV,EAIJ;AACDC,IAAAA,GAAG,EAAE,CAACC,OAAD,EAAUC,IAAV,EAAgBC,KAAhB,KAA0B;AAC7B,UAAI,CAACR,oBAAoB,CAACS,QAArB,CAA8BF,IAA9B,CAAL,EAA0C;AACxC,cAAM,IAAIG,KAAJ,CAAU,sCAAsCH,IAAtC,GAA6C,IAAvD,CAAN;AACD;;AAEDD,MAAAA,OAAO,CAACC,IAAD,CAAP,GAAgBC,KAAhB;AAEAZ,MAAAA,GAAG,CAACe,IAAJ,CAAS;AACPC,QAAAA,MAAM,EAAE;AACNL,UAAAA,IADM;AAENC,UAAAA;AAFM,SADD;AAKPK,QAAAA,gBAAgB,EAAEP;AALX,OAAT,EAMG,uBANH;AAQA,aAAO,IAAP;AACD;AAjBA,GAJI,CAAP;AAuBD,C","sourcesContent":["// @flow\n\nimport Logger from '../Logger';\n\ntype ProxyControllerType = {|\n HTTP_PROXY: string | null,\n HTTPS_PROXY: string | null,\n NO_PROXY: string | null,\n|};\n\nconst log = Logger.child({\n namespace: 'createProxyController',\n});\n\nconst KNOWN_PROPERTY_NAMES = [\n 'HTTP_PROXY',\n 'HTTPS_PROXY',\n 'NO_PROXY',\n];\n\nexport default (): ProxyControllerType => {\n // eslint-disable-next-line fp/no-proxy\n return new Proxy({\n HTTP_PROXY: null,\n HTTPS_PROXY: null,\n NO_PROXY: null,\n }, {\n set: (subject, name, value) => {\n if (!KNOWN_PROPERTY_NAMES.includes(name)) {\n throw new Error('Cannot set an unmapped property \"' + name + '\".');\n }\n\n subject[name] = value;\n\n log.info({\n change: {\n name,\n value,\n },\n newConfiguration: subject,\n }, 'configuration changed');\n\n return true;\n },\n });\n};\n"],"file":"createProxyController.js"}

View File

@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createGlobalProxyAgent", {
enumerable: true,
get: function () {
return _createGlobalProxyAgent.default;
}
});
Object.defineProperty(exports, "createProxyController", {
enumerable: true,
get: function () {
return _createProxyController.default;
}
});
var _createGlobalProxyAgent = _interopRequireDefault(require("./createGlobalProxyAgent"));
var _createProxyController = _interopRequireDefault(require("./createProxyController"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1,4 @@
// @flow
export {default as createGlobalProxyAgent} from './createGlobalProxyAgent';
export {default as createProxyController} from './createProxyController';

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/factories/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAEA;;AACA","sourcesContent":["// @flow\n\nexport {default as createGlobalProxyAgent} from './createGlobalProxyAgent';\nexport {default as createProxyController} from './createProxyController';\n"],"file":"index.js"}

22
buildfiles/node_modules/global-agent/dist/index.js generated vendored Normal file
View File

@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "bootstrap", {
enumerable: true,
get: function () {
return _routines.bootstrap;
}
});
Object.defineProperty(exports, "createGlobalProxyAgent", {
enumerable: true,
get: function () {
return _factories.createGlobalProxyAgent;
}
});
var _routines = require("./routines");
var _factories = require("./factories");
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1,4 @@
// @flow
export {bootstrap} from './routines';
export {createGlobalProxyAgent} from './factories';

View File

@ -0,0 +1 @@
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAEA;;AACA","sourcesContent":["// @flow\n\nexport {bootstrap} from './routines';\nexport {createGlobalProxyAgent} from './factories';\n"],"file":"index.js"}

View File

@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _Logger = _interopRequireDefault(require("../Logger"));
var _factories = require("../factories");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const log = _Logger.default.child({
namespace: 'bootstrap'
});
const bootstrap = configurationInput => {
if (global.GLOBAL_AGENT) {
log.warn('found global.GLOBAL_AGENT; second attempt to bootstrap global-agent was ignored');
return false;
}
global.GLOBAL_AGENT = (0, _factories.createGlobalProxyAgent)(configurationInput);
return true;
};
var _default = bootstrap;
exports.default = _default;
//# sourceMappingURL=bootstrap.js.map

View File

@ -0,0 +1,25 @@
// @flow
import Logger from '../Logger';
import {
createGlobalProxyAgent,
} from '../factories';
import type {
ProxyAgentConfigurationInputType,
} from '../types';
const log = Logger.child({
namespace: 'bootstrap',
});
export default (configurationInput?: ProxyAgentConfigurationInputType): boolean => {
if (global.GLOBAL_AGENT) {
log.warn('found global.GLOBAL_AGENT; second attempt to bootstrap global-agent was ignored');
return false;
}
global.GLOBAL_AGENT = createGlobalProxyAgent(configurationInput);
return true;
};

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/routines/bootstrap.js"],"names":["log","Logger","child","namespace","configurationInput","global","GLOBAL_AGENT","warn"],"mappings":";;;;;;;AAEA;;AACA;;;;AAOA,MAAMA,GAAG,GAAGC,gBAAOC,KAAP,CAAa;AACvBC,EAAAA,SAAS,EAAE;AADY,CAAb,CAAZ;;kBAIgBC,kB,IAAmE;AACjF,MAAIC,MAAM,CAACC,YAAX,EAAyB;AACvBN,IAAAA,GAAG,CAACO,IAAJ,CAAS,iFAAT;AAEA,WAAO,KAAP;AACD;;AAEDF,EAAAA,MAAM,CAACC,YAAP,GAAsB,uCAAuBF,kBAAvB,CAAtB;AAEA,SAAO,IAAP;AACD,C","sourcesContent":["// @flow\n\nimport Logger from '../Logger';\nimport {\n createGlobalProxyAgent,\n} from '../factories';\nimport type {\n ProxyAgentConfigurationInputType,\n} from '../types';\n\nconst log = Logger.child({\n namespace: 'bootstrap',\n});\n\nexport default (configurationInput?: ProxyAgentConfigurationInputType): boolean => {\n if (global.GLOBAL_AGENT) {\n log.warn('found global.GLOBAL_AGENT; second attempt to bootstrap global-agent was ignored');\n\n return false;\n }\n\n global.GLOBAL_AGENT = createGlobalProxyAgent(configurationInput);\n\n return true;\n};\n"],"file":"bootstrap.js"}

View File

@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "bootstrap", {
enumerable: true,
get: function () {
return _bootstrap.default;
}
});
var _bootstrap = _interopRequireDefault(require("./bootstrap"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1,3 @@
// @flow
export {default as bootstrap} from './bootstrap';

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/routines/index.js"],"names":[],"mappings":";;;;;;;;;;;;AAEA","sourcesContent":["// @flow\n\nexport {default as bootstrap} from './bootstrap';\n"],"file":"index.js"}

10
buildfiles/node_modules/global-agent/dist/types.js generated vendored Normal file
View File

@ -0,0 +1,10 @@
"use strict";
var _net = require("net");
var _tls = require("tls");
var _http = require("http");
var _https = require("https");
//# sourceMappingURL=types.js.map

View File

@ -0,0 +1,66 @@
// @flow
import {
Socket,
} from 'net';
import {
TLSSocket,
} from 'tls';
import {
Agent as HttpAgent,
} from 'http';
import {
Agent as HttpsAgent,
} from 'https';
export type ProxyConfigurationType = {|
+authorization: string,
+hostname: string,
+port: number,
|};
export type TlsConfigurationType = {|
+ca?: string,
+cert?: string,
+ciphers?: string,
+clientCertEngine?: string,
+crl?: string,
+dhparam?: string,
+ecdhCurve?: string,
+honorCipherOrder?: boolean,
+key?: string,
+passphrase?: string,
+pfx?: string,
+rejectUnauthorized?: boolean,
+secureOptions?: number,
+secureProtocol?: string,
+servername?: string,
+sessionIdContext?: string,
|};
export type ConnectionConfigurationType = {|
+host: string,
+port: number,
+tls?: TlsConfigurationType,
+proxy: ProxyConfigurationType,
|};
export type ConnectionCallbackType = (error: Error | null, socket?: Socket | TLSSocket) => void;
export type AgentType = HttpAgent | HttpsAgent;
export type IsProxyConfiguredMethodType = () => boolean;
export type MustUrlUseProxyMethodType = (url: string) => boolean;
export type GetUrlProxyMethodType = (url: string) => ProxyConfigurationType;
export type ProtocolType = 'http:' | 'https:';
export type ProxyAgentConfigurationInputType = {|
+environmentVariableNamespace?: string,
+forceGlobalAgent?: boolean,
+socketConnectionTimeout?: number,
|};
export type ProxyAgentConfigurationType = {|
+environmentVariableNamespace: string,
+forceGlobalAgent: boolean,
+socketConnectionTimeout: number,
|};

View File

@ -0,0 +1 @@
{"version":3,"sources":["../src/types.js"],"names":[],"mappings":";;AAEA;;AAGA;;AAGA;;AAGA","sourcesContent":["// @flow\n\nimport {\n Socket,\n} from 'net';\nimport {\n TLSSocket,\n} from 'tls';\nimport {\n Agent as HttpAgent,\n} from 'http';\nimport {\n Agent as HttpsAgent,\n} from 'https';\n\nexport type ProxyConfigurationType = {|\n +authorization: string,\n +hostname: string,\n +port: number,\n|};\n\nexport type TlsConfigurationType = {|\n +ca?: string,\n +cert?: string,\n +ciphers?: string,\n +clientCertEngine?: string,\n +crl?: string,\n +dhparam?: string,\n +ecdhCurve?: string,\n +honorCipherOrder?: boolean,\n +key?: string,\n +passphrase?: string,\n +pfx?: string,\n +rejectUnauthorized?: boolean,\n +secureOptions?: number,\n +secureProtocol?: string,\n +servername?: string,\n +sessionIdContext?: string,\n|};\n\nexport type ConnectionConfigurationType = {|\n +host: string,\n +port: number,\n +tls?: TlsConfigurationType,\n +proxy: ProxyConfigurationType,\n|};\n\nexport type ConnectionCallbackType = (error: Error | null, socket?: Socket | TLSSocket) => void;\n\nexport type AgentType = HttpAgent | HttpsAgent;\nexport type IsProxyConfiguredMethodType = () => boolean;\nexport type MustUrlUseProxyMethodType = (url: string) => boolean;\nexport type GetUrlProxyMethodType = (url: string) => ProxyConfigurationType;\nexport type ProtocolType = 'http:' | 'https:';\n\nexport type ProxyAgentConfigurationInputType = {|\n +environmentVariableNamespace?: string,\n +forceGlobalAgent?: boolean,\n +socketConnectionTimeout?: number,\n|};\n\nexport type ProxyAgentConfigurationType = {|\n +environmentVariableNamespace: string,\n +forceGlobalAgent: boolean,\n +socketConnectionTimeout: number,\n|};\n"],"file":"types.js"}

View File

@ -0,0 +1,62 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _http = _interopRequireDefault(require("http"));
var _https = _interopRequireDefault(require("https"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// eslint-disable-next-line flowtype/no-weak-types
const bindHttpMethod = (originalMethod, agent, forceGlobalAgent) => {
// eslint-disable-next-line unicorn/prevent-abbreviations
return (...args) => {
let url;
let options;
let callback;
if (typeof args[0] === 'string' || args[0] instanceof URL) {
url = args[0];
if (typeof args[1] === 'function') {
options = {};
callback = args[1];
} else {
options = { ...args[1]
};
callback = args[2];
}
} else {
options = { ...args[0]
};
callback = args[1];
}
if (forceGlobalAgent) {
options.agent = agent;
} else {
if (!options.agent) {
options.agent = agent;
}
if (options.agent === _http.default.globalAgent || options.agent === _https.default.globalAgent) {
options.agent = agent;
}
}
if (url) {
// $FlowFixMe
return originalMethod(url, options, callback);
} else {
return originalMethod(options, callback);
}
};
};
var _default = bindHttpMethod;
exports.default = _default;
//# sourceMappingURL=bindHttpMethod.js.map

View File

@ -0,0 +1,54 @@
// @flow
import http from 'http';
import https from 'https';
type AgentType = http.Agent | https.Agent;
// eslint-disable-next-line flowtype/no-weak-types
export default (originalMethod: Function, agent: AgentType, forceGlobalAgent: boolean) => {
// eslint-disable-next-line unicorn/prevent-abbreviations
return (...args: *) => {
let url;
let options;
let callback;
if (typeof args[0] === 'string' || args[0] instanceof URL) {
url = args[0];
if (typeof args[1] === 'function') {
options = {};
callback = args[1];
} else {
options = {
...args[1],
};
callback = args[2];
}
} else {
options = {
...args[0],
};
callback = args[1];
}
if (forceGlobalAgent) {
options.agent = agent;
} else {
if (!options.agent) {
options.agent = agent;
}
if (options.agent === http.globalAgent || options.agent === https.globalAgent) {
options.agent = agent;
}
}
if (url) {
// $FlowFixMe
return originalMethod(url, options, callback);
} else {
return originalMethod(options, callback);
}
};
};

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/bindHttpMethod.js"],"names":["originalMethod","agent","forceGlobalAgent","args","url","options","callback","URL","http","globalAgent","https"],"mappings":";;;;;;;AAEA;;AACA;;;;AAIA;wBACgBA,c,EAA0BC,K,EAAkBC,gB,KAA8B;AACxF;AACA,SAAO,CAAC,GAAGC,IAAJ,KAAgB;AACrB,QAAIC,GAAJ;AACA,QAAIC,OAAJ;AACA,QAAIC,QAAJ;;AAEA,QAAI,OAAOH,IAAI,CAAC,CAAD,CAAX,KAAmB,QAAnB,IAA+BA,IAAI,CAAC,CAAD,CAAJ,YAAmBI,GAAtD,EAA2D;AACzDH,MAAAA,GAAG,GAAGD,IAAI,CAAC,CAAD,CAAV;;AAEA,UAAI,OAAOA,IAAI,CAAC,CAAD,CAAX,KAAmB,UAAvB,EAAmC;AACjCE,QAAAA,OAAO,GAAG,EAAV;AACAC,QAAAA,QAAQ,GAAGH,IAAI,CAAC,CAAD,CAAf;AACD,OAHD,MAGO;AACLE,QAAAA,OAAO,GAAG,EACR,GAAGF,IAAI,CAAC,CAAD;AADC,SAAV;AAGAG,QAAAA,QAAQ,GAAGH,IAAI,CAAC,CAAD,CAAf;AACD;AACF,KAZD,MAYO;AACLE,MAAAA,OAAO,GAAG,EACR,GAAGF,IAAI,CAAC,CAAD;AADC,OAAV;AAGAG,MAAAA,QAAQ,GAAGH,IAAI,CAAC,CAAD,CAAf;AACD;;AAED,QAAID,gBAAJ,EAAsB;AACpBG,MAAAA,OAAO,CAACJ,KAAR,GAAgBA,KAAhB;AACD,KAFD,MAEO;AACL,UAAI,CAACI,OAAO,CAACJ,KAAb,EAAoB;AAClBI,QAAAA,OAAO,CAACJ,KAAR,GAAgBA,KAAhB;AACD;;AAED,UAAII,OAAO,CAACJ,KAAR,KAAkBO,cAAKC,WAAvB,IAAsCJ,OAAO,CAACJ,KAAR,KAAkBS,eAAMD,WAAlE,EAA+E;AAC7EJ,QAAAA,OAAO,CAACJ,KAAR,GAAgBA,KAAhB;AACD;AACF;;AAED,QAAIG,GAAJ,EAAS;AACP;AACA,aAAOJ,cAAc,CAACI,GAAD,EAAMC,OAAN,EAAeC,QAAf,CAArB;AACD,KAHD,MAGO;AACL,aAAON,cAAc,CAACK,OAAD,EAAUC,QAAV,CAArB;AACD;AACF,GA1CD;AA2CD,C","sourcesContent":["// @flow\n\nimport http from 'http';\nimport https from 'https';\n\ntype AgentType = http.Agent | https.Agent;\n\n// eslint-disable-next-line flowtype/no-weak-types\nexport default (originalMethod: Function, agent: AgentType, forceGlobalAgent: boolean) => {\n // eslint-disable-next-line unicorn/prevent-abbreviations\n return (...args: *) => {\n let url;\n let options;\n let callback;\n\n if (typeof args[0] === 'string' || args[0] instanceof URL) {\n url = args[0];\n\n if (typeof args[1] === 'function') {\n options = {};\n callback = args[1];\n } else {\n options = {\n ...args[1],\n };\n callback = args[2];\n }\n } else {\n options = {\n ...args[0],\n };\n callback = args[1];\n }\n\n if (forceGlobalAgent) {\n options.agent = agent;\n } else {\n if (!options.agent) {\n options.agent = agent;\n }\n\n if (options.agent === http.globalAgent || options.agent === https.globalAgent) {\n options.agent = agent;\n }\n }\n\n if (url) {\n // $FlowFixMe\n return originalMethod(url, options, callback);\n } else {\n return originalMethod(options, callback);\n }\n };\n};\n"],"file":"bindHttpMethod.js"}

View File

@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "bindHttpMethod", {
enumerable: true,
get: function () {
return _bindHttpMethod.default;
}
});
Object.defineProperty(exports, "isUrlMatchingNoProxy", {
enumerable: true,
get: function () {
return _isUrlMatchingNoProxy.default;
}
});
Object.defineProperty(exports, "parseProxyUrl", {
enumerable: true,
get: function () {
return _parseProxyUrl.default;
}
});
var _bindHttpMethod = _interopRequireDefault(require("./bindHttpMethod"));
var _isUrlMatchingNoProxy = _interopRequireDefault(require("./isUrlMatchingNoProxy"));
var _parseProxyUrl = _interopRequireDefault(require("./parseProxyUrl"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1,5 @@
// @flow
export {default as bindHttpMethod} from './bindHttpMethod';
export {default as isUrlMatchingNoProxy} from './isUrlMatchingNoProxy';
export {default as parseProxyUrl} from './parseProxyUrl';

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAEA;;AACA;;AACA","sourcesContent":["// @flow\n\nexport {default as bindHttpMethod} from './bindHttpMethod';\nexport {default as isUrlMatchingNoProxy} from './isUrlMatchingNoProxy';\nexport {default as parseProxyUrl} from './parseProxyUrl';\n"],"file":"index.js"}

View File

@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _url = require("url");
var _matcher = _interopRequireDefault(require("matcher"));
var _errors = require("../errors");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const isUrlMatchingNoProxy = (subjectUrl, noProxy) => {
const subjectUrlTokens = (0, _url.parse)(subjectUrl);
const rules = noProxy.split(/[\s,]/);
for (const rule of rules) {
const ruleMatch = rule.replace(/^(?<leadingDot>\.)/, '*').match(/^(?<hostname>.+?)(?::(?<port>\d+))?$/);
if (!ruleMatch || !ruleMatch.groups) {
throw new _errors.UnexpectedStateError('Invalid NO_PROXY pattern.');
}
if (!ruleMatch.groups.hostname) {
throw new _errors.UnexpectedStateError('NO_PROXY entry pattern must include hostname. Use * to match any hostname.');
}
const hostnameIsMatch = _matcher.default.isMatch(subjectUrlTokens.hostname, ruleMatch.groups.hostname);
if (hostnameIsMatch && (!ruleMatch.groups || !ruleMatch.groups.port || subjectUrlTokens.port && subjectUrlTokens.port === ruleMatch.groups.port)) {
return true;
}
}
return false;
};
var _default = isUrlMatchingNoProxy;
exports.default = _default;
//# sourceMappingURL=isUrlMatchingNoProxy.js.map

View File

@ -0,0 +1,37 @@
// @flow
import {
parse as parseUrl,
} from 'url';
import matcher from 'matcher';
import {
UnexpectedStateError,
} from '../errors';
export default (subjectUrl: string, noProxy: string) => {
const subjectUrlTokens = parseUrl(subjectUrl);
const rules = noProxy.split(/[\s,]/);
for (const rule of rules) {
const ruleMatch = rule
.replace(/^(?<leadingDot>\.)/, '*')
.match(/^(?<hostname>.+?)(?::(?<port>\d+))?$/);
if (!ruleMatch || !ruleMatch.groups) {
throw new UnexpectedStateError('Invalid NO_PROXY pattern.');
}
if (!ruleMatch.groups.hostname) {
throw new UnexpectedStateError('NO_PROXY entry pattern must include hostname. Use * to match any hostname.');
}
const hostnameIsMatch = matcher.isMatch(subjectUrlTokens.hostname, ruleMatch.groups.hostname);
if (hostnameIsMatch && (!ruleMatch.groups || !ruleMatch.groups.port || subjectUrlTokens.port && subjectUrlTokens.port === ruleMatch.groups.port)) {
return true;
}
}
return false;
};

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/isUrlMatchingNoProxy.js"],"names":["subjectUrl","noProxy","subjectUrlTokens","rules","split","rule","ruleMatch","replace","match","groups","UnexpectedStateError","hostname","hostnameIsMatch","matcher","isMatch","port"],"mappings":";;;;;;;AAEA;;AAGA;;AACA;;;;8BAIgBA,U,EAAoBC,O,KAAoB;AACtD,QAAMC,gBAAgB,GAAG,gBAASF,UAAT,CAAzB;AAEA,QAAMG,KAAK,GAAGF,OAAO,CAACG,KAAR,CAAc,OAAd,CAAd;;AAEA,OAAK,MAAMC,IAAX,IAAmBF,KAAnB,EAA0B;AACxB,UAAMG,SAAS,GAAGD,IAAI,CACnBE,OADe,CACP,oBADO,EACe,GADf,EAEfC,KAFe,CAET,sCAFS,CAAlB;;AAIA,QAAI,CAACF,SAAD,IAAc,CAACA,SAAS,CAACG,MAA7B,EAAqC;AACnC,YAAM,IAAIC,4BAAJ,CAAyB,2BAAzB,CAAN;AACD;;AAED,QAAI,CAACJ,SAAS,CAACG,MAAV,CAAiBE,QAAtB,EAAgC;AAC9B,YAAM,IAAID,4BAAJ,CAAyB,4EAAzB,CAAN;AACD;;AAED,UAAME,eAAe,GAAGC,iBAAQC,OAAR,CAAgBZ,gBAAgB,CAACS,QAAjC,EAA2CL,SAAS,CAACG,MAAV,CAAiBE,QAA5D,CAAxB;;AAEA,QAAIC,eAAe,KAAK,CAACN,SAAS,CAACG,MAAX,IAAqB,CAACH,SAAS,CAACG,MAAV,CAAiBM,IAAvC,IAA+Cb,gBAAgB,CAACa,IAAjB,IAAyBb,gBAAgB,CAACa,IAAjB,KAA0BT,SAAS,CAACG,MAAV,CAAiBM,IAAxH,CAAnB,EAAkJ;AAChJ,aAAO,IAAP;AACD;AACF;;AAED,SAAO,KAAP;AACD,C","sourcesContent":["// @flow\n\nimport {\n parse as parseUrl,\n} from 'url';\nimport matcher from 'matcher';\nimport {\n UnexpectedStateError,\n} from '../errors';\n\nexport default (subjectUrl: string, noProxy: string) => {\n const subjectUrlTokens = parseUrl(subjectUrl);\n\n const rules = noProxy.split(/[\\s,]/);\n\n for (const rule of rules) {\n const ruleMatch = rule\n .replace(/^(?<leadingDot>\\.)/, '*')\n .match(/^(?<hostname>.+?)(?::(?<port>\\d+))?$/);\n\n if (!ruleMatch || !ruleMatch.groups) {\n throw new UnexpectedStateError('Invalid NO_PROXY pattern.');\n }\n\n if (!ruleMatch.groups.hostname) {\n throw new UnexpectedStateError('NO_PROXY entry pattern must include hostname. Use * to match any hostname.');\n }\n\n const hostnameIsMatch = matcher.isMatch(subjectUrlTokens.hostname, ruleMatch.groups.hostname);\n\n if (hostnameIsMatch && (!ruleMatch.groups || !ruleMatch.groups.port || subjectUrlTokens.port && subjectUrlTokens.port === ruleMatch.groups.port)) {\n return true;\n }\n }\n\n return false;\n};\n"],"file":"isUrlMatchingNoProxy.js"}

View File

@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _url = require("url");
var _errors = require("../errors");
const parseProxyUrl = url => {
const urlTokens = (0, _url.parse)(url);
if (urlTokens.query !== null) {
throw new _errors.UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');
}
if (urlTokens.hash !== null) {
throw new _errors.UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');
}
if (urlTokens.protocol !== 'http:') {
throw new _errors.UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be "http:".');
}
let port = 80;
if (urlTokens.port) {
port = Number.parseInt(urlTokens.port, 10);
}
return {
authorization: urlTokens.auth || null,
hostname: urlTokens.hostname,
port
};
};
var _default = parseProxyUrl;
exports.default = _default;
//# sourceMappingURL=parseProxyUrl.js.map

View File

@ -0,0 +1,36 @@
// @flow
import {
parse as parseUrl,
} from 'url';
import {
UnexpectedStateError,
} from '../errors';
export default (url: string) => {
const urlTokens = parseUrl(url);
if (urlTokens.query !== null) {
throw new UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');
}
if (urlTokens.hash !== null) {
throw new UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');
}
if (urlTokens.protocol !== 'http:') {
throw new UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be "http:".');
}
let port = 80;
if (urlTokens.port) {
port = Number.parseInt(urlTokens.port, 10);
}
return {
authorization: urlTokens.auth || null,
hostname: urlTokens.hostname,
port,
};
};

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/utilities/parseProxyUrl.js"],"names":["url","urlTokens","query","UnexpectedStateError","hash","protocol","port","Number","parseInt","authorization","auth","hostname"],"mappings":";;;;;;;AAEA;;AAGA;;sBAIgBA,G,IAAgB;AAC9B,QAAMC,SAAS,GAAG,gBAASD,GAAT,CAAlB;;AAEA,MAAIC,SAAS,CAACC,KAAV,KAAoB,IAAxB,EAA8B;AAC5B,UAAM,IAAIC,4BAAJ,CAAyB,qFAAzB,CAAN;AACD;;AAED,MAAIF,SAAS,CAACG,IAAV,KAAmB,IAAvB,EAA6B;AAC3B,UAAM,IAAID,4BAAJ,CAAyB,oFAAzB,CAAN;AACD;;AAED,MAAIF,SAAS,CAACI,QAAV,KAAuB,OAA3B,EAAoC;AAClC,UAAM,IAAIF,4BAAJ,CAAyB,0FAAzB,CAAN;AACD;;AAED,MAAIG,IAAI,GAAG,EAAX;;AAEA,MAAIL,SAAS,CAACK,IAAd,EAAoB;AAClBA,IAAAA,IAAI,GAAGC,MAAM,CAACC,QAAP,CAAgBP,SAAS,CAACK,IAA1B,EAAgC,EAAhC,CAAP;AACD;;AAED,SAAO;AACLG,IAAAA,aAAa,EAAER,SAAS,CAACS,IAAV,IAAkB,IAD5B;AAELC,IAAAA,QAAQ,EAAEV,SAAS,CAACU,QAFf;AAGLL,IAAAA;AAHK,GAAP;AAKD,C","sourcesContent":["// @flow\n\nimport {\n parse as parseUrl,\n} from 'url';\nimport {\n UnexpectedStateError,\n} from '../errors';\n\nexport default (url: string) => {\n const urlTokens = parseUrl(url);\n\n if (urlTokens.query !== null) {\n throw new UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');\n }\n\n if (urlTokens.hash !== null) {\n throw new UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');\n }\n\n if (urlTokens.protocol !== 'http:') {\n throw new UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be \"http:\".');\n }\n\n let port = 80;\n\n if (urlTokens.port) {\n port = Number.parseInt(urlTokens.port, 10);\n }\n\n return {\n authorization: urlTokens.auth || null,\n hostname: urlTokens.hostname,\n port,\n };\n};\n"],"file":"parseProxyUrl.js"}

135
buildfiles/node_modules/global-agent/package.json generated vendored Normal file
View File

@ -0,0 +1,135 @@
{
"_from": "global-agent@^2.0.2",
"_id": "global-agent@2.1.12",
"_inBundle": false,
"_integrity": "sha512-caAljRMS/qcDo69X9BfkgrihGUgGx44Fb4QQToNQjsiWh+YlQ66uqYVAdA8Olqit+5Ng0nkz09je3ZzANMZcjg==",
"_location": "/global-agent",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "global-agent@^2.0.2",
"name": "global-agent",
"escapedName": "global-agent",
"rawSpec": "^2.0.2",
"saveSpec": null,
"fetchSpec": "^2.0.2"
},
"_requiredBy": [
"/@electron/get"
],
"_resolved": "https://registry.npmjs.org/global-agent/-/global-agent-2.1.12.tgz",
"_shasum": "e4ae3812b731a9e81cbf825f9377ef450a8e4195",
"_spec": "global-agent@^2.0.2",
"_where": "/home/shihaam/www/freezer.shihaam.me/node_modules/@electron/get",
"author": {
"name": "Gajus Kuizinas",
"email": "gajus@gajus.com",
"url": "http://gajus.com"
},
"ava": {
"babel": {
"compileAsTests": [
"test/helpers/**/*"
]
},
"files": [
"test/global-agent/**/*"
],
"require": [
"@babel/register"
]
},
"bugs": {
"url": "https://github.com/gajus/global-agent/issues"
},
"bundleDependencies": false,
"dependencies": {
"boolean": "^3.0.1",
"core-js": "^3.6.5",
"es6-error": "^4.1.1",
"matcher": "^3.0.0",
"roarr": "^2.15.3",
"semver": "^7.3.2",
"serialize-error": "^7.0.1"
},
"deprecated": false,
"description": "Global HTTP/HTTPS proxy configurable using environment variables.",
"devDependencies": {
"@ava/babel": "^1.0.1",
"@babel/cli": "^7.10.1",
"@babel/core": "^7.10.2",
"@babel/node": "^7.10.1",
"@babel/plugin-transform-flow-strip-types": "^7.10.1",
"@babel/preset-env": "^7.10.2",
"@babel/register": "^7.10.1",
"anyproxy": "^4.1.2",
"ava": "^3.8.2",
"axios": "^0.19.2",
"babel-plugin-istanbul": "^6.0.0",
"babel-plugin-transform-export-default-name": "^2.0.4",
"coveralls": "^3.1.0",
"eslint": "^7.1.0",
"eslint-config-canonical": "^20.0.5",
"flow-bin": "^0.125.1",
"flow-copy-source": "^2.0.9",
"get-port": "^5.1.1",
"got": "^11.1.4",
"husky": "^4.2.5",
"nyc": "^15.1.0",
"pem": "^1.14.4",
"request": "^2.88.2",
"semantic-release": "^17.0.8",
"sinon": "^9.0.2"
},
"engines": {
"node": ">=10.0"
},
"homepage": "https://github.com/gajus/global-agent#readme",
"husky": {
"hooks": {
"pre-commit": "npm run lint && npm run test && npm run build"
}
},
"keywords": [
"http",
"global",
"proxy",
"agent"
],
"license": "BSD-3-Clause",
"main": "./dist/index.js",
"name": "global-agent",
"nyc": {
"all": true,
"exclude": [
"src/bin",
"src/queries/*.js"
],
"include": [
"src/**/*.js"
],
"instrument": false,
"reporter": [
"html",
"text-summary"
],
"require": [
"@babel/register"
],
"silent": true,
"sourceMap": false
},
"repository": {
"type": "git",
"url": "git+https://github.com/gajus/global-agent.git"
},
"scripts": {
"build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist",
"create-readme": "gitdown ./.README/README.md --output-file ./README.md",
"dev": "NODE_ENV=development babel ./src --out-dir ./dist --copy-files --source-maps --watch",
"lint": "eslint ./src ./test && flow",
"test": "NODE_TLS_REJECT_UNAUTHORIZED=false NODE_ENV=test nyc ava --verbose --serial"
},
"version": "2.1.12"
}

10
buildfiles/node_modules/global-agent/src/Logger.js generated vendored Normal file
View File

@ -0,0 +1,10 @@
// @flow
import Roarr from 'roarr';
const Logger = Roarr
.child({
package: 'global-agent',
});
export default Logger;

View File

@ -0,0 +1,212 @@
// @flow
import {
serializeError,
} from 'serialize-error';
import {
boolean,
} from 'boolean';
import Logger from '../Logger';
import type {
AgentType,
GetUrlProxyMethodType,
IsProxyConfiguredMethodType,
MustUrlUseProxyMethodType,
ProtocolType,
} from '../types';
const log = Logger.child({
namespace: 'Agent',
});
let requestId = 0;
class Agent {
defaultPort: number;
protocol: ProtocolType;
fallbackAgent: AgentType;
isProxyConfigured: IsProxyConfiguredMethodType;
mustUrlUseProxy: MustUrlUseProxyMethodType;
getUrlProxy: GetUrlProxyMethodType;
socketConnectionTimeout: number;
constructor (
isProxyConfigured: IsProxyConfiguredMethodType,
mustUrlUseProxy: MustUrlUseProxyMethodType,
getUrlProxy: GetUrlProxyMethodType,
fallbackAgent: AgentType,
socketConnectionTimeout: number,
) {
this.fallbackAgent = fallbackAgent;
this.isProxyConfigured = isProxyConfigured;
this.mustUrlUseProxy = mustUrlUseProxy;
this.getUrlProxy = getUrlProxy;
this.socketConnectionTimeout = socketConnectionTimeout;
}
addRequest (request: *, configuration: *) {
let requestUrl;
// It is possible that addRequest was constructed for a proxied request already, e.g.
// "request" package does this when it detects that a proxy should be used
// https://github.com/request/request/blob/212570b6971a732b8dd9f3c73354bcdda158a737/request.js#L402
// https://gist.github.com/gajus/e2074cd3b747864ffeaabbd530d30218
if (request.path.startsWith('http://') || request.path.startsWith('https://')) {
requestUrl = request.path;
} else {
requestUrl = this.protocol + '//' + (configuration.hostname || configuration.host) + (configuration.port === 80 || configuration.port === 443 ? '' : ':' + configuration.port) + request.path;
}
if (!this.isProxyConfigured()) {
log.trace({
destination: requestUrl,
}, 'not proxying request; GLOBAL_AGENT.HTTP_PROXY is not configured');
// $FlowFixMe It appears that Flow is missing the method description.
this.fallbackAgent.addRequest(request, configuration);
return;
}
if (!this.mustUrlUseProxy(requestUrl)) {
log.trace({
destination: requestUrl,
}, 'not proxying request; url matches GLOBAL_AGENT.NO_PROXY');
// $FlowFixMe It appears that Flow is missing the method description.
this.fallbackAgent.addRequest(request, configuration);
return;
}
const currentRequestId = requestId++;
const proxy = this.getUrlProxy(requestUrl);
if (this.protocol === 'http:') {
request.path = requestUrl;
if (proxy.authorization) {
request.setHeader('proxy-authorization', 'Basic ' + Buffer.from(proxy.authorization).toString('base64'));
}
}
log.trace({
destination: requestUrl,
proxy: 'http://' + proxy.hostname + ':' + proxy.port,
requestId: currentRequestId,
}, 'proxying request');
request.on('error', (error) => {
log.error({
error: serializeError(error),
}, 'request error');
});
request.once('response', (response) => {
log.trace({
headers: response.headers,
requestId: currentRequestId,
statusCode: response.statusCode,
}, 'proxying response');
});
request.shouldKeepAlive = false;
const connectionConfiguration = {
host: configuration.hostname || configuration.host,
port: configuration.port || 80,
proxy,
tls: {},
};
// add optional tls options for https requests.
// @see https://nodejs.org/docs/latest-v12.x/api/https.html#https_https_request_url_options_callback :
// > The following additional options from tls.connect()
// > - https://nodejs.org/docs/latest-v12.x/api/tls.html#tls_tls_connect_options_callback -
// > are also accepted:
// > ca, cert, ciphers, clientCertEngine, crl, dhparam, ecdhCurve, honorCipherOrder,
// > key, passphrase, pfx, rejectUnauthorized, secureOptions, secureProtocol, servername, sessionIdContext.
if (this.protocol === 'https:') {
connectionConfiguration.tls = {
ca: configuration.ca,
cert: configuration.cert,
ciphers: configuration.ciphers,
clientCertEngine: configuration.clientCertEngine,
crl: configuration.crl,
dhparam: configuration.dhparam,
ecdhCurve: configuration.ecdhCurve,
honorCipherOrder: configuration.honorCipherOrder,
key: configuration.key,
passphrase: configuration.passphrase,
pfx: configuration.pfx,
rejectUnauthorized: configuration.rejectUnauthorized,
secureOptions: configuration.secureOptions,
secureProtocol: configuration.secureProtocol,
servername: configuration.servername || connectionConfiguration.host,
sessionIdContext: configuration.sessionIdContext,
};
// This is not ideal because there is no way to override this setting using `tls` configuration if `NODE_TLS_REJECT_UNAUTHORIZED=0`.
// However, popular HTTP clients (such as https://github.com/sindresorhus/got) come with pre-configured value for `rejectUnauthorized`,
// which makes it impossible to override that value globally and respect `rejectUnauthorized` for specific requests only.
//
// eslint-disable-next-line no-process-env
if (typeof process.env.NODE_TLS_REJECT_UNAUTHORIZED === 'string' && boolean(process.env.NODE_TLS_REJECT_UNAUTHORIZED) === false) {
connectionConfiguration.tls.rejectUnauthorized = false;
}
}
// $FlowFixMe It appears that Flow is missing the method description.
this.createConnection(connectionConfiguration, (error, socket) => {
log.trace({
target: connectionConfiguration,
}, 'connecting');
// @see https://github.com/nodejs/node/issues/5757#issuecomment-305969057
if (socket) {
socket.setTimeout(this.socketConnectionTimeout, () => {
socket.destroy();
});
socket.once('connect', () => {
log.trace({
target: connectionConfiguration,
}, 'connected');
socket.setTimeout(0);
});
socket.once('secureConnect', () => {
log.trace({
target: connectionConfiguration,
}, 'connected (secure)');
socket.setTimeout(0);
});
}
if (error) {
request.emit('error', error);
} else {
log.debug('created socket');
socket.on('error', (socketError) => {
log.error({
error: serializeError(socketError),
}, 'socket error');
});
request.onSocket(socket);
}
});
}
}
export default Agent;

View File

@ -0,0 +1,30 @@
// @flow
import net from 'net';
import type {
ConnectionCallbackType,
ConnectionConfigurationType,
} from '../types';
import Agent from './Agent';
class HttpProxyAgent extends Agent {
// @see https://github.com/sindresorhus/eslint-plugin-unicorn/issues/169#issuecomment-486980290
// eslint-disable-next-line unicorn/prevent-abbreviations
constructor (...args: *) {
super(...args);
this.protocol = 'http:';
this.defaultPort = 80;
}
createConnection (configuration: ConnectionConfigurationType, callback: ConnectionCallbackType) {
const socket = net.connect(
configuration.proxy.port,
configuration.proxy.hostname,
);
callback(null, socket);
}
}
export default HttpProxyAgent;

View File

@ -0,0 +1,54 @@
// @flow
import net from 'net';
import tls from 'tls';
import type {
ConnectionCallbackType,
ConnectionConfigurationType,
} from '../types';
import Agent from './Agent';
class HttpsProxyAgent extends Agent {
// eslint-disable-next-line unicorn/prevent-abbreviations
constructor (...args: *) {
super(...args);
this.protocol = 'https:';
this.defaultPort = 443;
}
createConnection (configuration: ConnectionConfigurationType, callback: ConnectionCallbackType) {
const socket = net.connect(
configuration.proxy.port,
configuration.proxy.hostname,
);
socket.on('error', (error) => {
callback(error);
});
socket.once('data', () => {
const secureSocket = tls.connect({
...configuration.tls,
socket,
});
callback(null, secureSocket);
});
let connectMessage = '';
connectMessage += 'CONNECT ' + configuration.host + ':' + configuration.port + ' HTTP/1.1\r\n';
connectMessage += 'Host: ' + configuration.host + ':' + configuration.port + '\r\n';
if (configuration.proxy.authorization) {
connectMessage += 'Proxy-Authorization: Basic ' + Buffer.from(configuration.proxy.authorization).toString('base64') + '\r\n';
}
connectMessage += '\r\n';
socket.write(connectMessage);
}
}
export default HttpsProxyAgent;

View File

@ -0,0 +1,5 @@
// @flow
export {default as Agent} from './Agent';
export {default as HttpProxyAgent} from './HttpProxyAgent';
export {default as HttpsProxyAgent} from './HttpsProxyAgent';

15
buildfiles/node_modules/global-agent/src/errors.js generated vendored Normal file
View File

@ -0,0 +1,15 @@
// @flow
/* eslint-disable fp/no-class, fp/no-this */
import ExtendableError from 'es6-error';
export class UnexpectedStateError extends ExtendableError {
code: string;
constructor (message: string, code: string = 'UNEXPECTED_STATE_ERROR') {
super(message);
this.code = code;
}
}

View File

@ -0,0 +1,197 @@
// @flow
import http from 'http';
import https from 'https';
import {
boolean as parseBoolean,
} from 'boolean';
import semver from 'semver';
import Logger from '../Logger';
import {
HttpProxyAgent,
HttpsProxyAgent,
} from '../classes';
import {
UnexpectedStateError,
} from '../errors';
import {
bindHttpMethod,
isUrlMatchingNoProxy,
parseProxyUrl,
} from '../utilities';
import type {
ProxyAgentConfigurationInputType,
ProxyAgentConfigurationType,
} from '../types';
import createProxyController from './createProxyController';
const httpGet = http.get;
const httpRequest = http.request;
const httpsGet = https.get;
const httpsRequest = https.request;
const log = Logger.child({
namespace: 'createGlobalProxyAgent',
});
const defaultConfigurationInput = {
environmentVariableNamespace: undefined,
forceGlobalAgent: undefined,
socketConnectionTimeout: 60000,
};
const omitUndefined = (subject) => {
const keys = Object.keys(subject);
const result = {};
for (const key of keys) {
const value = subject[key];
if (value !== undefined) {
result[key] = value;
}
}
return result;
};
const createConfiguration = (configurationInput: ProxyAgentConfigurationInputType): ProxyAgentConfigurationType => {
// eslint-disable-next-line no-process-env
const environment = process.env;
const defaultConfiguration = {
environmentVariableNamespace: typeof environment.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE === 'string' ? environment.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE : 'GLOBAL_AGENT_',
forceGlobalAgent: typeof environment.GLOBAL_AGENT_FORCE_GLOBAL_AGENT === 'string' ? parseBoolean(environment.GLOBAL_AGENT_FORCE_GLOBAL_AGENT) : true,
socketConnectionTimeout: typeof environment.GLOBAL_AGENT_SOCKET_CONNECTION_TIMEOUT === 'string' ? Number.parseInt(environment.GLOBAL_AGENT_SOCKET_CONNECTION_TIMEOUT, 10) : defaultConfigurationInput.socketConnectionTimeout,
};
// $FlowFixMe
return {
...defaultConfiguration,
...omitUndefined(configurationInput),
};
};
export default (configurationInput: ProxyAgentConfigurationInputType = defaultConfigurationInput) => {
const configuration = createConfiguration(configurationInput);
const proxyController = createProxyController();
// eslint-disable-next-line no-process-env
proxyController.HTTP_PROXY = process.env[configuration.environmentVariableNamespace + 'HTTP_PROXY'] || null;
// eslint-disable-next-line no-process-env
proxyController.HTTPS_PROXY = process.env[configuration.environmentVariableNamespace + 'HTTPS_PROXY'] || null;
// eslint-disable-next-line no-process-env
proxyController.NO_PROXY = process.env[configuration.environmentVariableNamespace + 'NO_PROXY'] || null;
log.info({
configuration,
state: proxyController,
}, 'global agent has been initialized');
const mustUrlUseProxy = (getProxy) => {
return (url) => {
if (!getProxy()) {
return false;
}
if (!proxyController.NO_PROXY) {
return true;
}
return !isUrlMatchingNoProxy(url, proxyController.NO_PROXY);
};
};
const getUrlProxy = (getProxy) => {
return () => {
const proxy = getProxy();
if (!proxy) {
throw new UnexpectedStateError('HTTP(S) proxy must be configured.');
}
return parseProxyUrl(proxy);
};
};
const getHttpProxy = () => {
return proxyController.HTTP_PROXY;
};
const BoundHttpProxyAgent = class extends HttpProxyAgent {
constructor () {
super(
() => {
return getHttpProxy();
},
mustUrlUseProxy(getHttpProxy),
getUrlProxy(getHttpProxy),
http.globalAgent,
configuration.socketConnectionTimeout,
);
}
};
const httpAgent = new BoundHttpProxyAgent();
const getHttpsProxy = () => {
return proxyController.HTTPS_PROXY || proxyController.HTTP_PROXY;
};
const BoundHttpsProxyAgent = class extends HttpsProxyAgent {
constructor () {
super(
() => {
return getHttpsProxy();
},
mustUrlUseProxy(getHttpsProxy),
getUrlProxy(getHttpsProxy),
https.globalAgent,
configuration.socketConnectionTimeout,
);
}
};
const httpsAgent = new BoundHttpsProxyAgent();
// Overriding globalAgent was added in v11.7.
// @see https://nodejs.org/uk/blog/release/v11.7.0/
if (semver.gte(process.version, 'v11.7.0')) {
// @see https://github.com/facebook/flow/issues/7670
// $FlowFixMe
http.globalAgent = httpAgent;
// $FlowFixMe
https.globalAgent = httpsAgent;
}
// The reason this logic is used in addition to overriding http(s).globalAgent
// is because there is no guarantee that we set http(s).globalAgent variable
// before an instance of http(s).Agent has been already constructed by someone,
// e.g. Stripe SDK creates instances of http(s).Agent at the top-level.
// @see https://github.com/gajus/global-agent/pull/13
//
// We still want to override http(s).globalAgent when possible to enable logic
// in `bindHttpMethod`.
if (semver.gte(process.version, 'v10.0.0')) {
// $FlowFixMe
http.get = bindHttpMethod(httpGet, httpAgent, configuration.forceGlobalAgent);
// $FlowFixMe
http.request = bindHttpMethod(httpRequest, httpAgent, configuration.forceGlobalAgent);
// $FlowFixMe
https.get = bindHttpMethod(httpsGet, httpsAgent, configuration.forceGlobalAgent);
// $FlowFixMe
https.request = bindHttpMethod(httpsRequest, httpsAgent, configuration.forceGlobalAgent);
} else {
log.warn('attempt to initialize global-agent in unsupported Node.js version was ignored');
}
return proxyController;
};

View File

@ -0,0 +1,46 @@
// @flow
import Logger from '../Logger';
type ProxyControllerType = {|
HTTP_PROXY: string | null,
HTTPS_PROXY: string | null,
NO_PROXY: string | null,
|};
const log = Logger.child({
namespace: 'createProxyController',
});
const KNOWN_PROPERTY_NAMES = [
'HTTP_PROXY',
'HTTPS_PROXY',
'NO_PROXY',
];
export default (): ProxyControllerType => {
// eslint-disable-next-line fp/no-proxy
return new Proxy({
HTTP_PROXY: null,
HTTPS_PROXY: null,
NO_PROXY: null,
}, {
set: (subject, name, value) => {
if (!KNOWN_PROPERTY_NAMES.includes(name)) {
throw new Error('Cannot set an unmapped property "' + name + '".');
}
subject[name] = value;
log.info({
change: {
name,
value,
},
newConfiguration: subject,
}, 'configuration changed');
return true;
},
});
};

View File

@ -0,0 +1,4 @@
// @flow
export {default as createGlobalProxyAgent} from './createGlobalProxyAgent';
export {default as createProxyController} from './createProxyController';

4
buildfiles/node_modules/global-agent/src/index.js generated vendored Normal file
View File

@ -0,0 +1,4 @@
// @flow
export {bootstrap} from './routines';
export {createGlobalProxyAgent} from './factories';

View File

@ -0,0 +1,25 @@
// @flow
import Logger from '../Logger';
import {
createGlobalProxyAgent,
} from '../factories';
import type {
ProxyAgentConfigurationInputType,
} from '../types';
const log = Logger.child({
namespace: 'bootstrap',
});
export default (configurationInput?: ProxyAgentConfigurationInputType): boolean => {
if (global.GLOBAL_AGENT) {
log.warn('found global.GLOBAL_AGENT; second attempt to bootstrap global-agent was ignored');
return false;
}
global.GLOBAL_AGENT = createGlobalProxyAgent(configurationInput);
return true;
};

View File

@ -0,0 +1,3 @@
// @flow
export {default as bootstrap} from './bootstrap';

66
buildfiles/node_modules/global-agent/src/types.js generated vendored Normal file
View File

@ -0,0 +1,66 @@
// @flow
import {
Socket,
} from 'net';
import {
TLSSocket,
} from 'tls';
import {
Agent as HttpAgent,
} from 'http';
import {
Agent as HttpsAgent,
} from 'https';
export type ProxyConfigurationType = {|
+authorization: string,
+hostname: string,
+port: number,
|};
export type TlsConfigurationType = {|
+ca?: string,
+cert?: string,
+ciphers?: string,
+clientCertEngine?: string,
+crl?: string,
+dhparam?: string,
+ecdhCurve?: string,
+honorCipherOrder?: boolean,
+key?: string,
+passphrase?: string,
+pfx?: string,
+rejectUnauthorized?: boolean,
+secureOptions?: number,
+secureProtocol?: string,
+servername?: string,
+sessionIdContext?: string,
|};
export type ConnectionConfigurationType = {|
+host: string,
+port: number,
+tls?: TlsConfigurationType,
+proxy: ProxyConfigurationType,
|};
export type ConnectionCallbackType = (error: Error | null, socket?: Socket | TLSSocket) => void;
export type AgentType = HttpAgent | HttpsAgent;
export type IsProxyConfiguredMethodType = () => boolean;
export type MustUrlUseProxyMethodType = (url: string) => boolean;
export type GetUrlProxyMethodType = (url: string) => ProxyConfigurationType;
export type ProtocolType = 'http:' | 'https:';
export type ProxyAgentConfigurationInputType = {|
+environmentVariableNamespace?: string,
+forceGlobalAgent?: boolean,
+socketConnectionTimeout?: number,
|};
export type ProxyAgentConfigurationType = {|
+environmentVariableNamespace: string,
+forceGlobalAgent: boolean,
+socketConnectionTimeout: number,
|};

View File

@ -0,0 +1,54 @@
// @flow
import http from 'http';
import https from 'https';
type AgentType = http.Agent | https.Agent;
// eslint-disable-next-line flowtype/no-weak-types
export default (originalMethod: Function, agent: AgentType, forceGlobalAgent: boolean) => {
// eslint-disable-next-line unicorn/prevent-abbreviations
return (...args: *) => {
let url;
let options;
let callback;
if (typeof args[0] === 'string' || args[0] instanceof URL) {
url = args[0];
if (typeof args[1] === 'function') {
options = {};
callback = args[1];
} else {
options = {
...args[1],
};
callback = args[2];
}
} else {
options = {
...args[0],
};
callback = args[1];
}
if (forceGlobalAgent) {
options.agent = agent;
} else {
if (!options.agent) {
options.agent = agent;
}
if (options.agent === http.globalAgent || options.agent === https.globalAgent) {
options.agent = agent;
}
}
if (url) {
// $FlowFixMe
return originalMethod(url, options, callback);
} else {
return originalMethod(options, callback);
}
};
};

View File

@ -0,0 +1,5 @@
// @flow
export {default as bindHttpMethod} from './bindHttpMethod';
export {default as isUrlMatchingNoProxy} from './isUrlMatchingNoProxy';
export {default as parseProxyUrl} from './parseProxyUrl';

View File

@ -0,0 +1,37 @@
// @flow
import {
parse as parseUrl,
} from 'url';
import matcher from 'matcher';
import {
UnexpectedStateError,
} from '../errors';
export default (subjectUrl: string, noProxy: string) => {
const subjectUrlTokens = parseUrl(subjectUrl);
const rules = noProxy.split(/[\s,]/);
for (const rule of rules) {
const ruleMatch = rule
.replace(/^(?<leadingDot>\.)/, '*')
.match(/^(?<hostname>.+?)(?::(?<port>\d+))?$/);
if (!ruleMatch || !ruleMatch.groups) {
throw new UnexpectedStateError('Invalid NO_PROXY pattern.');
}
if (!ruleMatch.groups.hostname) {
throw new UnexpectedStateError('NO_PROXY entry pattern must include hostname. Use * to match any hostname.');
}
const hostnameIsMatch = matcher.isMatch(subjectUrlTokens.hostname, ruleMatch.groups.hostname);
if (hostnameIsMatch && (!ruleMatch.groups || !ruleMatch.groups.port || subjectUrlTokens.port && subjectUrlTokens.port === ruleMatch.groups.port)) {
return true;
}
}
return false;
};

View File

@ -0,0 +1,36 @@
// @flow
import {
parse as parseUrl,
} from 'url';
import {
UnexpectedStateError,
} from '../errors';
export default (url: string) => {
const urlTokens = parseUrl(url);
if (urlTokens.query !== null) {
throw new UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');
}
if (urlTokens.hash !== null) {
throw new UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');
}
if (urlTokens.protocol !== 'http:') {
throw new UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be "http:".');
}
let port = 80;
if (urlTokens.port) {
port = Number.parseInt(urlTokens.port, 10);
}
return {
authorization: urlTokens.auth || null,
hostname: urlTokens.hostname,
port,
};
};