global-agent 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +23 -0
- package/.editorconfig +9 -0
- package/.eslintignore +1 -0
- package/.eslintrc +27 -0
- package/.github/FUNDING.yml +2 -0
- package/.github/workflows/feature.yaml +32 -0
- package/.github/workflows/main.yaml +31 -0
- package/.gitignore +14 -0
- package/LICENSE +2 -2
- package/README.md +67 -8
- package/package.json +48 -56
- package/src/{Logger.js → Logger.ts} +3 -3
- package/{dist/classes/Agent.js.flow → src/classes/Agent.ts} +121 -39
- package/src/classes/HttpProxyAgent.ts +45 -0
- package/src/classes/HttpsProxyAgent.ts +83 -0
- package/src/classes/index.ts +9 -0
- package/src/{errors.js → errors.ts} +2 -6
- package/src/factories/{createGlobalProxyAgent.js → createGlobalProxyAgent.ts} +36 -50
- package/{dist/factories/createProxyController.js.flow → src/factories/createProxyController.ts} +8 -5
- package/src/factories/index.ts +6 -0
- package/src/index.ts +6 -0
- package/{dist/routines/bootstrap.js.flow → src/routines/bootstrap.ts} +6 -5
- package/src/routines/index.ts +3 -0
- package/src/types.ts +66 -0
- package/src/utilities/{bindHttpMethod.js → bindHttpMethod.ts} +6 -7
- package/src/utilities/index.ts +9 -0
- package/{dist/utilities/isUrlMatchingNoProxy.js.flow → src/utilities/isUrlMatchingNoProxy.ts} +1 -6
- package/src/utilities/parseBoolean.ts +17 -0
- package/src/utilities/{parseProxyUrl.js → parseProxyUrl.ts} +12 -9
- package/test/.eslintrc +10 -0
- package/test/global-agent/factories/createGlobalProxyAgent.ts +760 -0
- package/test/global-agent/factories/createProxyController.ts +37 -0
- package/test/global-agent/utilities/isUrlMatchingNoProxy.ts +62 -0
- package/test/global-agent/utilities/parseProxyUrl.ts +38 -0
- package/tsconfig.json +25 -0
- package/.flowconfig +0 -3
- package/dist/Logger.js +0 -18
- package/dist/Logger.js.flow +0 -10
- package/dist/Logger.js.map +0 -1
- package/dist/classes/Agent.js +0 -174
- package/dist/classes/Agent.js.map +0 -1
- package/dist/classes/HttpProxyAgent.js +0 -33
- package/dist/classes/HttpProxyAgent.js.flow +0 -30
- package/dist/classes/HttpProxyAgent.js.map +0 -1
- package/dist/classes/HttpsProxyAgent.js +0 -53
- package/dist/classes/HttpsProxyAgent.js.flow +0 -54
- package/dist/classes/HttpsProxyAgent.js.map +0 -1
- package/dist/classes/index.js +0 -32
- package/dist/classes/index.js.flow +0 -5
- package/dist/classes/index.js.map +0 -1
- package/dist/errors.js +0 -22
- package/dist/errors.js.flow +0 -15
- package/dist/errors.js.map +0 -1
- package/dist/factories/createGlobalProxyAgent.js +0 -175
- package/dist/factories/createGlobalProxyAgent.js.flow +0 -197
- package/dist/factories/createGlobalProxyAgent.js.map +0 -1
- package/dist/factories/createProxyController.js +0 -45
- package/dist/factories/createProxyController.js.map +0 -1
- package/dist/factories/index.js +0 -24
- package/dist/factories/index.js.flow +0 -4
- package/dist/factories/index.js.map +0 -1
- package/dist/index.js +0 -22
- package/dist/index.js.flow +0 -4
- package/dist/index.js.map +0 -1
- package/dist/routines/bootstrap.js +0 -30
- package/dist/routines/bootstrap.js.map +0 -1
- package/dist/routines/index.js +0 -16
- package/dist/routines/index.js.flow +0 -3
- package/dist/routines/index.js.map +0 -1
- package/dist/types.js +0 -10
- package/dist/types.js.flow +0 -66
- package/dist/types.js.map +0 -1
- package/dist/utilities/bindHttpMethod.js +0 -62
- package/dist/utilities/bindHttpMethod.js.flow +0 -54
- package/dist/utilities/bindHttpMethod.js.map +0 -1
- package/dist/utilities/index.js +0 -32
- package/dist/utilities/index.js.flow +0 -5
- package/dist/utilities/index.js.map +0 -1
- package/dist/utilities/isUrlMatchingNoProxy.js +0 -43
- package/dist/utilities/isUrlMatchingNoProxy.js.map +0 -1
- package/dist/utilities/parseProxyUrl.js +0 -42
- package/dist/utilities/parseProxyUrl.js.flow +0 -36
- package/dist/utilities/parseProxyUrl.js.map +0 -1
- package/src/classes/Agent.js +0 -212
- package/src/classes/HttpProxyAgent.js +0 -30
- package/src/classes/HttpsProxyAgent.js +0 -54
- package/src/classes/index.js +0 -5
- package/src/factories/createProxyController.js +0 -46
- package/src/factories/index.js +0 -4
- package/src/index.js +0 -4
- package/src/routines/bootstrap.js +0 -25
- package/src/routines/index.js +0 -3
- package/src/types.js +0 -66
- package/src/utilities/index.js +0 -5
- package/src/utilities/isUrlMatchingNoProxy.js +0 -37
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import Logger from '../Logger';
|
|
4
|
-
|
|
5
|
-
type ProxyControllerType = {|
|
|
6
|
-
HTTP_PROXY: string | null,
|
|
7
|
-
HTTPS_PROXY: string | null,
|
|
8
|
-
NO_PROXY: string | null,
|
|
9
|
-
|};
|
|
10
|
-
|
|
11
|
-
const log = Logger.child({
|
|
12
|
-
namespace: 'createProxyController',
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const KNOWN_PROPERTY_NAMES = [
|
|
16
|
-
'HTTP_PROXY',
|
|
17
|
-
'HTTPS_PROXY',
|
|
18
|
-
'NO_PROXY',
|
|
19
|
-
];
|
|
20
|
-
|
|
21
|
-
export default (): ProxyControllerType => {
|
|
22
|
-
// eslint-disable-next-line fp/no-proxy
|
|
23
|
-
return new Proxy({
|
|
24
|
-
HTTP_PROXY: null,
|
|
25
|
-
HTTPS_PROXY: null,
|
|
26
|
-
NO_PROXY: null,
|
|
27
|
-
}, {
|
|
28
|
-
set: (subject, name, value) => {
|
|
29
|
-
if (!KNOWN_PROPERTY_NAMES.includes(name)) {
|
|
30
|
-
throw new Error('Cannot set an unmapped property "' + name + '".');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
subject[name] = value;
|
|
34
|
-
|
|
35
|
-
log.info({
|
|
36
|
-
change: {
|
|
37
|
-
name,
|
|
38
|
-
value,
|
|
39
|
-
},
|
|
40
|
-
newConfiguration: subject,
|
|
41
|
-
}, 'configuration changed');
|
|
42
|
-
|
|
43
|
-
return true;
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
};
|
package/src/factories/index.js
DELETED
package/src/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import Logger from '../Logger';
|
|
4
|
-
import {
|
|
5
|
-
createGlobalProxyAgent,
|
|
6
|
-
} from '../factories';
|
|
7
|
-
import type {
|
|
8
|
-
ProxyAgentConfigurationInputType,
|
|
9
|
-
} from '../types';
|
|
10
|
-
|
|
11
|
-
const log = Logger.child({
|
|
12
|
-
namespace: 'bootstrap',
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export default (configurationInput?: ProxyAgentConfigurationInputType): boolean => {
|
|
16
|
-
if (global.GLOBAL_AGENT) {
|
|
17
|
-
log.warn('found global.GLOBAL_AGENT; second attempt to bootstrap global-agent was ignored');
|
|
18
|
-
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
global.GLOBAL_AGENT = createGlobalProxyAgent(configurationInput);
|
|
23
|
-
|
|
24
|
-
return true;
|
|
25
|
-
};
|
package/src/routines/index.js
DELETED
package/src/types.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
Socket,
|
|
5
|
-
} from 'net';
|
|
6
|
-
import {
|
|
7
|
-
TLSSocket,
|
|
8
|
-
} from 'tls';
|
|
9
|
-
import {
|
|
10
|
-
Agent as HttpAgent,
|
|
11
|
-
} from 'http';
|
|
12
|
-
import {
|
|
13
|
-
Agent as HttpsAgent,
|
|
14
|
-
} from 'https';
|
|
15
|
-
|
|
16
|
-
export type ProxyConfigurationType = {|
|
|
17
|
-
+authorization: string,
|
|
18
|
-
+hostname: string,
|
|
19
|
-
+port: number,
|
|
20
|
-
|};
|
|
21
|
-
|
|
22
|
-
export type TlsConfigurationType = {|
|
|
23
|
-
+ca?: string,
|
|
24
|
-
+cert?: string,
|
|
25
|
-
+ciphers?: string,
|
|
26
|
-
+clientCertEngine?: string,
|
|
27
|
-
+crl?: string,
|
|
28
|
-
+dhparam?: string,
|
|
29
|
-
+ecdhCurve?: string,
|
|
30
|
-
+honorCipherOrder?: boolean,
|
|
31
|
-
+key?: string,
|
|
32
|
-
+passphrase?: string,
|
|
33
|
-
+pfx?: string,
|
|
34
|
-
+rejectUnauthorized?: boolean,
|
|
35
|
-
+secureOptions?: number,
|
|
36
|
-
+secureProtocol?: string,
|
|
37
|
-
+servername?: string,
|
|
38
|
-
+sessionIdContext?: string,
|
|
39
|
-
|};
|
|
40
|
-
|
|
41
|
-
export type ConnectionConfigurationType = {|
|
|
42
|
-
+host: string,
|
|
43
|
-
+port: number,
|
|
44
|
-
+tls?: TlsConfigurationType,
|
|
45
|
-
+proxy: ProxyConfigurationType,
|
|
46
|
-
|};
|
|
47
|
-
|
|
48
|
-
export type ConnectionCallbackType = (error: Error | null, socket?: Socket | TLSSocket) => void;
|
|
49
|
-
|
|
50
|
-
export type AgentType = HttpAgent | HttpsAgent;
|
|
51
|
-
export type IsProxyConfiguredMethodType = () => boolean;
|
|
52
|
-
export type MustUrlUseProxyMethodType = (url: string) => boolean;
|
|
53
|
-
export type GetUrlProxyMethodType = (url: string) => ProxyConfigurationType;
|
|
54
|
-
export type ProtocolType = 'http:' | 'https:';
|
|
55
|
-
|
|
56
|
-
export type ProxyAgentConfigurationInputType = {|
|
|
57
|
-
+environmentVariableNamespace?: string,
|
|
58
|
-
+forceGlobalAgent?: boolean,
|
|
59
|
-
+socketConnectionTimeout?: number,
|
|
60
|
-
|};
|
|
61
|
-
|
|
62
|
-
export type ProxyAgentConfigurationType = {|
|
|
63
|
-
+environmentVariableNamespace: string,
|
|
64
|
-
+forceGlobalAgent: boolean,
|
|
65
|
-
+socketConnectionTimeout: number,
|
|
66
|
-
|};
|
package/src/utilities/index.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
parse as parseUrl,
|
|
5
|
-
} from 'url';
|
|
6
|
-
import matcher from 'matcher';
|
|
7
|
-
import {
|
|
8
|
-
UnexpectedStateError,
|
|
9
|
-
} from '../errors';
|
|
10
|
-
|
|
11
|
-
export default (subjectUrl: string, noProxy: string) => {
|
|
12
|
-
const subjectUrlTokens = parseUrl(subjectUrl);
|
|
13
|
-
|
|
14
|
-
const rules = noProxy.split(/[\s,]+/);
|
|
15
|
-
|
|
16
|
-
for (const rule of rules) {
|
|
17
|
-
const ruleMatch = rule
|
|
18
|
-
.replace(/^(?<leadingDot>\.)/, '*')
|
|
19
|
-
.match(/^(?<hostname>.+?)(?::(?<port>\d+))?$/);
|
|
20
|
-
|
|
21
|
-
if (!ruleMatch || !ruleMatch.groups) {
|
|
22
|
-
throw new UnexpectedStateError('Invalid NO_PROXY pattern.');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!ruleMatch.groups.hostname) {
|
|
26
|
-
throw new UnexpectedStateError('NO_PROXY entry pattern must include hostname. Use * to match any hostname.');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const hostnameIsMatch = matcher.isMatch(subjectUrlTokens.hostname, ruleMatch.groups.hostname);
|
|
30
|
-
|
|
31
|
-
if (hostnameIsMatch && (!ruleMatch.groups || !ruleMatch.groups.port || subjectUrlTokens.port && subjectUrlTokens.port === ruleMatch.groups.port)) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return false;
|
|
37
|
-
};
|