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.
Files changed (95) hide show
  1. package/.babelrc +23 -0
  2. package/.editorconfig +9 -0
  3. package/.eslintignore +1 -0
  4. package/.eslintrc +27 -0
  5. package/.github/FUNDING.yml +2 -0
  6. package/.github/workflows/feature.yaml +32 -0
  7. package/.github/workflows/main.yaml +31 -0
  8. package/.gitignore +14 -0
  9. package/LICENSE +2 -2
  10. package/README.md +67 -8
  11. package/package.json +48 -56
  12. package/src/{Logger.js → Logger.ts} +3 -3
  13. package/{dist/classes/Agent.js.flow → src/classes/Agent.ts} +121 -39
  14. package/src/classes/HttpProxyAgent.ts +45 -0
  15. package/src/classes/HttpsProxyAgent.ts +83 -0
  16. package/src/classes/index.ts +9 -0
  17. package/src/{errors.js → errors.ts} +2 -6
  18. package/src/factories/{createGlobalProxyAgent.js → createGlobalProxyAgent.ts} +36 -50
  19. package/{dist/factories/createProxyController.js.flow → src/factories/createProxyController.ts} +8 -5
  20. package/src/factories/index.ts +6 -0
  21. package/src/index.ts +6 -0
  22. package/{dist/routines/bootstrap.js.flow → src/routines/bootstrap.ts} +6 -5
  23. package/src/routines/index.ts +3 -0
  24. package/src/types.ts +66 -0
  25. package/src/utilities/{bindHttpMethod.js → bindHttpMethod.ts} +6 -7
  26. package/src/utilities/index.ts +9 -0
  27. package/{dist/utilities/isUrlMatchingNoProxy.js.flow → src/utilities/isUrlMatchingNoProxy.ts} +1 -6
  28. package/src/utilities/parseBoolean.ts +17 -0
  29. package/src/utilities/{parseProxyUrl.js → parseProxyUrl.ts} +12 -9
  30. package/test/.eslintrc +10 -0
  31. package/test/global-agent/factories/createGlobalProxyAgent.ts +760 -0
  32. package/test/global-agent/factories/createProxyController.ts +37 -0
  33. package/test/global-agent/utilities/isUrlMatchingNoProxy.ts +62 -0
  34. package/test/global-agent/utilities/parseProxyUrl.ts +38 -0
  35. package/tsconfig.json +25 -0
  36. package/.flowconfig +0 -3
  37. package/dist/Logger.js +0 -18
  38. package/dist/Logger.js.flow +0 -10
  39. package/dist/Logger.js.map +0 -1
  40. package/dist/classes/Agent.js +0 -174
  41. package/dist/classes/Agent.js.map +0 -1
  42. package/dist/classes/HttpProxyAgent.js +0 -33
  43. package/dist/classes/HttpProxyAgent.js.flow +0 -30
  44. package/dist/classes/HttpProxyAgent.js.map +0 -1
  45. package/dist/classes/HttpsProxyAgent.js +0 -53
  46. package/dist/classes/HttpsProxyAgent.js.flow +0 -54
  47. package/dist/classes/HttpsProxyAgent.js.map +0 -1
  48. package/dist/classes/index.js +0 -32
  49. package/dist/classes/index.js.flow +0 -5
  50. package/dist/classes/index.js.map +0 -1
  51. package/dist/errors.js +0 -22
  52. package/dist/errors.js.flow +0 -15
  53. package/dist/errors.js.map +0 -1
  54. package/dist/factories/createGlobalProxyAgent.js +0 -175
  55. package/dist/factories/createGlobalProxyAgent.js.flow +0 -197
  56. package/dist/factories/createGlobalProxyAgent.js.map +0 -1
  57. package/dist/factories/createProxyController.js +0 -45
  58. package/dist/factories/createProxyController.js.map +0 -1
  59. package/dist/factories/index.js +0 -24
  60. package/dist/factories/index.js.flow +0 -4
  61. package/dist/factories/index.js.map +0 -1
  62. package/dist/index.js +0 -22
  63. package/dist/index.js.flow +0 -4
  64. package/dist/index.js.map +0 -1
  65. package/dist/routines/bootstrap.js +0 -30
  66. package/dist/routines/bootstrap.js.map +0 -1
  67. package/dist/routines/index.js +0 -16
  68. package/dist/routines/index.js.flow +0 -3
  69. package/dist/routines/index.js.map +0 -1
  70. package/dist/types.js +0 -10
  71. package/dist/types.js.flow +0 -66
  72. package/dist/types.js.map +0 -1
  73. package/dist/utilities/bindHttpMethod.js +0 -62
  74. package/dist/utilities/bindHttpMethod.js.flow +0 -54
  75. package/dist/utilities/bindHttpMethod.js.map +0 -1
  76. package/dist/utilities/index.js +0 -32
  77. package/dist/utilities/index.js.flow +0 -5
  78. package/dist/utilities/index.js.map +0 -1
  79. package/dist/utilities/isUrlMatchingNoProxy.js +0 -43
  80. package/dist/utilities/isUrlMatchingNoProxy.js.map +0 -1
  81. package/dist/utilities/parseProxyUrl.js +0 -42
  82. package/dist/utilities/parseProxyUrl.js.flow +0 -36
  83. package/dist/utilities/parseProxyUrl.js.map +0 -1
  84. package/src/classes/Agent.js +0 -212
  85. package/src/classes/HttpProxyAgent.js +0 -30
  86. package/src/classes/HttpsProxyAgent.js +0 -54
  87. package/src/classes/index.js +0 -5
  88. package/src/factories/createProxyController.js +0 -46
  89. package/src/factories/index.js +0 -4
  90. package/src/index.js +0 -4
  91. package/src/routines/bootstrap.js +0 -25
  92. package/src/routines/index.js +0 -3
  93. package/src/types.js +0 -66
  94. package/src/utilities/index.js +0 -5
  95. package/src/utilities/isUrlMatchingNoProxy.js +0 -37
@@ -0,0 +1,37 @@
1
+ import test from 'ava';
2
+ import createProxyController from '../../../src/factories/createProxyController';
3
+
4
+ test('sets HTTP_PROXY', (t) => {
5
+ const globalAgentGlobal = createProxyController();
6
+
7
+ globalAgentGlobal.HTTP_PROXY = 'http://127.0.0.1';
8
+
9
+ t.is(globalAgentGlobal.HTTP_PROXY, 'http://127.0.0.1');
10
+ });
11
+
12
+ test('sets HTTPS_PROXY', (t) => {
13
+ const globalAgentGlobal = createProxyController();
14
+
15
+ globalAgentGlobal.HTTPS_PROXY = 'http://127.0.0.1';
16
+
17
+ t.is(globalAgentGlobal.HTTPS_PROXY, 'http://127.0.0.1');
18
+ });
19
+
20
+ test('sets NO_PROXY', (t) => {
21
+ const globalAgentGlobal = createProxyController();
22
+
23
+ globalAgentGlobal.NO_PROXY = '*';
24
+
25
+ t.is(globalAgentGlobal.NO_PROXY, '*');
26
+ });
27
+
28
+ test('throws an error if unknown property is set', (t) => {
29
+ const globalAgentGlobal = createProxyController();
30
+
31
+ const error = t.throws(() => {
32
+ // @ts-expect-error expected unknown property.
33
+ globalAgentGlobal.FOO = 'BAR';
34
+ });
35
+
36
+ t.is(error.message, 'Cannot set an unmapped property "FOO".');
37
+ });
@@ -0,0 +1,62 @@
1
+ import test from 'ava';
2
+ import isUrlMatchingNoProxy from '../../../src/utilities/isUrlMatchingNoProxy';
3
+
4
+ test('returns `true` if hosts match', (t) => {
5
+ t.assert(isUrlMatchingNoProxy('http://foo.com/', 'foo.com'));
6
+ });
7
+
8
+ test('returns `true` if hosts match (IP)', (t) => {
9
+ t.assert(isUrlMatchingNoProxy('http://127.0.0.1/', '127.0.0.1'));
10
+ });
11
+
12
+ test('returns `true` if hosts match (using asterisk wildcard)', (t) => {
13
+ t.assert(isUrlMatchingNoProxy('http://bar.foo.com/', '*.foo.com'));
14
+ });
15
+
16
+ test('returns `true` if domain matches (using dot wildcard)', (t) => {
17
+ t.assert(isUrlMatchingNoProxy('http://foo.com/', '.foo.com'));
18
+ });
19
+
20
+ test('returns `true` if subdomain matches (using dot wildcard)', (t) => {
21
+ t.assert(isUrlMatchingNoProxy('http://bar.foo.com/', '.foo.com'));
22
+ });
23
+
24
+ test('returns `true` if hosts match (*) and ports match', (t) => {
25
+ t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', '*:8080'));
26
+ });
27
+
28
+ test('returns `true` if hosts and ports match', (t) => {
29
+ t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com:8080'));
30
+ });
31
+
32
+ test('returns `true` if hosts match and NO_PROXY does not define port', (t) => {
33
+ t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com'));
34
+ });
35
+
36
+ test('returns `true` if hosts (IP) and ports match', (t) => {
37
+ t.assert(isUrlMatchingNoProxy('http://127.0.0.1:8080/', '127.0.0.1:8080'));
38
+ });
39
+
40
+ test('returns `false` if hosts match and ports do not match (diffferent port)', (t) => {
41
+ t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com:8000') === false);
42
+ });
43
+
44
+ test('returns `false` if hosts match and ports do not match (port not present subject)', (t) => {
45
+ t.assert(isUrlMatchingNoProxy('http://foo.com/', 'foo.com:8000') === false);
46
+ });
47
+
48
+ test('returns `true` if hosts match and ports do not match (port not present NO_PROXY)', (t) => {
49
+ t.assert(isUrlMatchingNoProxy('http://foo.com:8000/', 'foo.com'));
50
+ });
51
+
52
+ test('returns `true` if hosts match in one of multiple rules separated with a comma', (t) => {
53
+ t.assert(isUrlMatchingNoProxy('http://foo.com/', 'bar.org,foo.com,baz.io'));
54
+ });
55
+
56
+ test('returns `true` if hosts match in one of multiple rules separated with a comma and a space', (t) => {
57
+ t.assert(isUrlMatchingNoProxy('http://foo.com/', 'bar.org, foo.com, baz.io'));
58
+ });
59
+
60
+ test('returns `true` if hosts match in one of multiple rules separated with a space', (t) => {
61
+ t.assert(isUrlMatchingNoProxy('http://foo.com/', 'bar.org foo.com baz.io'));
62
+ });
@@ -0,0 +1,38 @@
1
+ import test from 'ava';
2
+ import parseProxyUrl from '../../../src/utilities/parseProxyUrl';
3
+
4
+ test('extracts hostname', (t) => {
5
+ t.is(parseProxyUrl('http://0.0.0.0').hostname, '0.0.0.0');
6
+ });
7
+
8
+ test('extracts port', (t) => {
9
+ t.is(parseProxyUrl('http://0.0.0.0:3000').port, 3_000);
10
+ });
11
+
12
+ test('extracts authorization', (t) => {
13
+ t.is(parseProxyUrl('http://foo:bar@0.0.0.0').authorization, 'foo:bar');
14
+ });
15
+
16
+ test('throws an error if protocol is not "http:"', (t) => {
17
+ const error = t.throws(() => {
18
+ parseProxyUrl('https://0.0.0.0:3000');
19
+ });
20
+
21
+ t.is(error.message, 'Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be "http:".');
22
+ });
23
+
24
+ test('throws an error if query is present', (t) => {
25
+ const error = t.throws(() => {
26
+ parseProxyUrl('http://0.0.0.0:3000/?foo=bar');
27
+ });
28
+
29
+ t.is(error.message, 'Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');
30
+ });
31
+
32
+ test('throws an error if hash is present', (t) => {
33
+ const error = t.throws(() => {
34
+ parseProxyUrl('http://0.0.0.0:3000/#foo');
35
+ });
36
+
37
+ t.is(error.message, 'Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');
38
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowSyntheticDefaultImports": true,
4
+ "declaration": true,
5
+ "esModuleInterop": true,
6
+ "module": "commonjs",
7
+ "moduleResolution": "node",
8
+ "noImplicitReturns": true,
9
+ "noUnusedLocals": false,
10
+ "noUnusedParameters": false,
11
+ "outDir": "dist",
12
+ "skipLibCheck": true,
13
+ "strict": true,
14
+ "strictPropertyInitialization": false,
15
+ "target": "es2018"
16
+ },
17
+ "exclude": [
18
+ "dist",
19
+ "node_modules"
20
+ ],
21
+ "include": [
22
+ "src",
23
+ "test"
24
+ ]
25
+ }
package/.flowconfig DELETED
@@ -1,3 +0,0 @@
1
- [ignore]
2
- .*/node_modules/.*/test/.*
3
- <PROJECT_ROOT>/dist/.*
package/dist/Logger.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _roarr = _interopRequireDefault(require("roarr"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- const Logger = _roarr.default.child({
13
- package: 'global-agent'
14
- });
15
-
16
- var _default = Logger;
17
- exports.default = _default;
18
- //# sourceMappingURL=Logger.js.map
@@ -1,10 +0,0 @@
1
- // @flow
2
-
3
- import Roarr from 'roarr';
4
-
5
- const Logger = Roarr
6
- .child({
7
- package: 'global-agent',
8
- });
9
-
10
- export default Logger;
@@ -1 +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"}
@@ -1,174 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _serializeError = require("serialize-error");
9
-
10
- var _boolean = require("boolean");
11
-
12
- var _Logger = _interopRequireDefault(require("../Logger"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const log = _Logger.default.child({
17
- namespace: 'Agent'
18
- });
19
-
20
- let requestId = 0;
21
-
22
- class Agent {
23
- constructor(isProxyConfigured, mustUrlUseProxy, getUrlProxy, fallbackAgent, socketConnectionTimeout) {
24
- this.fallbackAgent = fallbackAgent;
25
- this.isProxyConfigured = isProxyConfigured;
26
- this.mustUrlUseProxy = mustUrlUseProxy;
27
- this.getUrlProxy = getUrlProxy;
28
- this.socketConnectionTimeout = socketConnectionTimeout;
29
- }
30
-
31
- addRequest(request, configuration) {
32
- let requestUrl; // It is possible that addRequest was constructed for a proxied request already, e.g.
33
- // "request" package does this when it detects that a proxy should be used
34
- // https://github.com/request/request/blob/212570b6971a732b8dd9f3c73354bcdda158a737/request.js#L402
35
- // https://gist.github.com/gajus/e2074cd3b747864ffeaabbd530d30218
36
-
37
- if (request.path.startsWith('http://') || request.path.startsWith('https://')) {
38
- requestUrl = request.path;
39
- } else {
40
- requestUrl = this.protocol + '//' + (configuration.hostname || configuration.host) + (configuration.port === 80 || configuration.port === 443 ? '' : ':' + configuration.port) + request.path;
41
- }
42
-
43
- if (!this.isProxyConfigured()) {
44
- log.trace({
45
- destination: requestUrl
46
- }, 'not proxying request; GLOBAL_AGENT.HTTP_PROXY is not configured'); // $FlowFixMe It appears that Flow is missing the method description.
47
-
48
- this.fallbackAgent.addRequest(request, configuration);
49
- return;
50
- }
51
-
52
- if (!this.mustUrlUseProxy(requestUrl)) {
53
- log.trace({
54
- destination: requestUrl
55
- }, 'not proxying request; url matches GLOBAL_AGENT.NO_PROXY'); // $FlowFixMe It appears that Flow is missing the method description.
56
-
57
- this.fallbackAgent.addRequest(request, configuration);
58
- return;
59
- }
60
-
61
- const currentRequestId = requestId++;
62
- const proxy = this.getUrlProxy(requestUrl);
63
-
64
- if (this.protocol === 'http:') {
65
- request.path = requestUrl;
66
-
67
- if (proxy.authorization) {
68
- request.setHeader('proxy-authorization', 'Basic ' + Buffer.from(proxy.authorization).toString('base64'));
69
- }
70
- }
71
-
72
- log.trace({
73
- destination: requestUrl,
74
- proxy: 'http://' + proxy.hostname + ':' + proxy.port,
75
- requestId: currentRequestId
76
- }, 'proxying request');
77
- request.on('error', error => {
78
- log.error({
79
- error: (0, _serializeError.serializeError)(error)
80
- }, 'request error');
81
- });
82
- request.once('response', response => {
83
- log.trace({
84
- headers: response.headers,
85
- requestId: currentRequestId,
86
- statusCode: response.statusCode
87
- }, 'proxying response');
88
- });
89
- request.shouldKeepAlive = false;
90
- const connectionConfiguration = {
91
- host: configuration.hostname || configuration.host,
92
- port: configuration.port || 80,
93
- proxy,
94
- tls: {}
95
- }; // add optional tls options for https requests.
96
- // @see https://nodejs.org/docs/latest-v12.x/api/https.html#https_https_request_url_options_callback :
97
- // > The following additional options from tls.connect()
98
- // > - https://nodejs.org/docs/latest-v12.x/api/tls.html#tls_tls_connect_options_callback -
99
- // > are also accepted:
100
- // > ca, cert, ciphers, clientCertEngine, crl, dhparam, ecdhCurve, honorCipherOrder,
101
- // > key, passphrase, pfx, rejectUnauthorized, secureOptions, secureProtocol, servername, sessionIdContext.
102
-
103
- if (this.protocol === 'https:') {
104
- connectionConfiguration.tls = {
105
- ca: configuration.ca,
106
- cert: configuration.cert,
107
- ciphers: configuration.ciphers,
108
- clientCertEngine: configuration.clientCertEngine,
109
- crl: configuration.crl,
110
- dhparam: configuration.dhparam,
111
- ecdhCurve: configuration.ecdhCurve,
112
- honorCipherOrder: configuration.honorCipherOrder,
113
- key: configuration.key,
114
- passphrase: configuration.passphrase,
115
- pfx: configuration.pfx,
116
- rejectUnauthorized: configuration.rejectUnauthorized,
117
- secureOptions: configuration.secureOptions,
118
- secureProtocol: configuration.secureProtocol,
119
- servername: configuration.servername || connectionConfiguration.host,
120
- sessionIdContext: configuration.sessionIdContext
121
- }; // This is not ideal because there is no way to override this setting using `tls` configuration if `NODE_TLS_REJECT_UNAUTHORIZED=0`.
122
- // However, popular HTTP clients (such as https://github.com/sindresorhus/got) come with pre-configured value for `rejectUnauthorized`,
123
- // which makes it impossible to override that value globally and respect `rejectUnauthorized` for specific requests only.
124
- //
125
- // eslint-disable-next-line no-process-env
126
-
127
- if (typeof process.env.NODE_TLS_REJECT_UNAUTHORIZED === 'string' && (0, _boolean.boolean)(process.env.NODE_TLS_REJECT_UNAUTHORIZED) === false) {
128
- connectionConfiguration.tls.rejectUnauthorized = false;
129
- }
130
- } // $FlowFixMe It appears that Flow is missing the method description.
131
-
132
-
133
- this.createConnection(connectionConfiguration, (error, socket) => {
134
- log.trace({
135
- target: connectionConfiguration
136
- }, 'connecting'); // @see https://github.com/nodejs/node/issues/5757#issuecomment-305969057
137
-
138
- if (socket) {
139
- socket.setTimeout(this.socketConnectionTimeout, () => {
140
- socket.destroy();
141
- });
142
- socket.once('connect', () => {
143
- log.trace({
144
- target: connectionConfiguration
145
- }, 'connected');
146
- socket.setTimeout(0);
147
- });
148
- socket.once('secureConnect', () => {
149
- log.trace({
150
- target: connectionConfiguration
151
- }, 'connected (secure)');
152
- socket.setTimeout(0);
153
- });
154
- }
155
-
156
- if (error) {
157
- request.emit('error', error);
158
- } else {
159
- log.debug('created socket');
160
- socket.on('error', socketError => {
161
- log.error({
162
- error: (0, _serializeError.serializeError)(socketError)
163
- }, 'socket error');
164
- });
165
- request.onSocket(socket);
166
- }
167
- });
168
- }
169
-
170
- }
171
-
172
- var _default = Agent;
173
- exports.default = _default;
174
- //# sourceMappingURL=Agent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/classes/Agent.js"],"names":["log","Logger","child","namespace","requestId","Agent","constructor","isProxyConfigured","mustUrlUseProxy","getUrlProxy","fallbackAgent","socketConnectionTimeout","addRequest","request","configuration","requestUrl","path","startsWith","protocol","hostname","host","port","trace","destination","currentRequestId","proxy","authorization","setHeader","Buffer","from","toString","on","error","once","response","headers","statusCode","shouldKeepAlive","connectionConfiguration","tls","ca","cert","ciphers","clientCertEngine","crl","dhparam","ecdhCurve","honorCipherOrder","key","passphrase","pfx","rejectUnauthorized","secureOptions","secureProtocol","servername","sessionIdContext","process","env","NODE_TLS_REJECT_UNAUTHORIZED","createConnection","socket","target","setTimeout","destroy","emit","debug","socketError","onSocket"],"mappings":";;;;;;;AAEA;;AAGA;;AAGA;;;;AASA,MAAMA,GAAG,GAAGC,gBAAOC,KAAP,CAAa;AACvBC,EAAAA,SAAS,EAAE;AADY,CAAb,CAAZ;;AAIA,IAAIC,SAAS,GAAG,CAAhB;;AAEA,MAAMC,KAAN,CAAY;AAeVC,EAAAA,WAAW,CACTC,iBADS,EAETC,eAFS,EAGTC,WAHS,EAITC,aAJS,EAKTC,uBALS,EAMT;AACA,SAAKD,aAAL,GAAqBA,aAArB;AACA,SAAKH,iBAAL,GAAyBA,iBAAzB;AACA,SAAKC,eAAL,GAAuBA,eAAvB;AACA,SAAKC,WAAL,GAAmBA,WAAnB;AACA,SAAKE,uBAAL,GAA+BA,uBAA/B;AACD;;AAEDC,EAAAA,UAAU,CAAEC,OAAF,EAAcC,aAAd,EAAgC;AACxC,QAAIC,UAAJ,CADwC,CAGxC;AACA;AACA;AACA;;AACA,QAAIF,OAAO,CAACG,IAAR,CAAaC,UAAb,CAAwB,SAAxB,KAAsCJ,OAAO,CAACG,IAAR,CAAaC,UAAb,CAAwB,UAAxB,CAA1C,EAA+E;AAC7EF,MAAAA,UAAU,GAAGF,OAAO,CAACG,IAArB;AACD,KAFD,MAEO;AACLD,MAAAA,UAAU,GAAG,KAAKG,QAA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3BjC,UAAAA,GAAG,CAACsB,KAAJ,CAAU;AACRuC,YAAAA,MAAM,EAAEvB;AADA,WAAV,EAEG,WAFH;AAIAsB,UAAAA,MAAM,CAACE,UAAP,CAAkB,CAAlB;AACD,SAND;AAQAF,QAAAA,MAAM,CAAC3B,IAAP,CAAY,eAAZ,EAA6B,MAAM;AACjCjC,UAAAA,GAAG,CAACsB,KAAJ,CAAU;AACRuC,YAAAA,MAAM,EAAEvB;AADA,WAAV,EAEG,oBAFH;AAIAsB,UAAAA,MAAM,CAACE,UAAP,CAAkB,CAAlB;AACD,SAND;AAOD;;AAED,UAAI9B,KAAJ,EAAW;AACTnB,QAAAA,OAAO,CAACmD,IAAR,CAAa,OAAb,EAAsBhC,KAAtB;AACD,OAFD,MAEO;AACLhC,QAAAA,GAAG,CAACiE,KAAJ,CAAU,gBAAV;AAEAL,QAAAA,MAAM,CAAC7B,EAAP,CAAU,OAAV,EAAoBmC,WAAD,IAAiB;AAClClE,UAAAA,GAAG,CAACgC,KAAJ,CAAU;AACRA,YAAAA,KAAK,EAAE,oCAAekC,WAAf;AADC,WAAV,EAEG,cAFH;AAGD,SAJD;AAMArD,QAAAA,OAAO,CAACsD,QAAR,CAAiBP,MAAjB;AACD;AACF,KAzCD;AA0CD;;AAzLS;;eA4LGvD,K","sourcesContent":["// @flow\n\nimport {\n serializeError,\n} from 'serialize-error';\nimport {\n boolean,\n} from 'boolean';\nimport Logger from '../Logger';\nimport type {\n AgentType,\n GetUrlProxyMethodType,\n IsProxyConfiguredMethodType,\n MustUrlUseProxyMethodType,\n ProtocolType,\n} from '../types';\n\nconst log = Logger.child({\n namespace: 'Agent',\n});\n\nlet requestId = 0;\n\nclass Agent {\n defaultPort: number;\n\n protocol: ProtocolType;\n\n fallbackAgent: AgentType;\n\n isProxyConfigured: IsProxyConfiguredMethodType;\n\n mustUrlUseProxy: MustUrlUseProxyMethodType;\n\n getUrlProxy: GetUrlProxyMethodType;\n\n socketConnectionTimeout: number;\n\n constructor (\n isProxyConfigured: IsProxyConfiguredMethodType,\n mustUrlUseProxy: MustUrlUseProxyMethodType,\n getUrlProxy: GetUrlProxyMethodType,\n fallbackAgent: AgentType,\n socketConnectionTimeout: number,\n ) {\n this.fallbackAgent = fallbackAgent;\n this.isProxyConfigured = isProxyConfigured;\n this.mustUrlUseProxy = mustUrlUseProxy;\n this.getUrlProxy = getUrlProxy;\n this.socketConnectionTimeout = socketConnectionTimeout;\n }\n\n addRequest (request: *, configuration: *) {\n let requestUrl;\n\n // It is possible that addRequest was constructed for a proxied request already, e.g.\n // \"request\" package does this when it detects that a proxy should be used\n // https://github.com/request/request/blob/212570b6971a732b8dd9f3c73354bcdda158a737/request.js#L402\n // https://gist.github.com/gajus/e2074cd3b747864ffeaabbd530d30218\n if (request.path.startsWith('http://') || request.path.startsWith('https://')) {\n requestUrl = request.path;\n } else {\n requestUrl = this.protocol + '//' + (configuration.hostname || configuration.host) + (configuration.port === 80 || configuration.port === 443 ? '' : ':' + configuration.port) + request.path;\n }\n\n if (!this.isProxyConfigured()) {\n log.trace({\n destination: requestUrl,\n }, 'not proxying request; GLOBAL_AGENT.HTTP_PROXY is not configured');\n\n // $FlowFixMe It appears that Flow is missing the method description.\n this.fallbackAgent.addRequest(request, configuration);\n\n return;\n }\n\n if (!this.mustUrlUseProxy(requestUrl)) {\n log.trace({\n destination: requestUrl,\n }, 'not proxying request; url matches GLOBAL_AGENT.NO_PROXY');\n\n // $FlowFixMe It appears that Flow is missing the method description.\n this.fallbackAgent.addRequest(request, configuration);\n\n return;\n }\n\n const currentRequestId = requestId++;\n\n const proxy = this.getUrlProxy(requestUrl);\n\n if (this.protocol === 'http:') {\n request.path = requestUrl;\n\n if (proxy.authorization) {\n request.setHeader('proxy-authorization', 'Basic ' + Buffer.from(proxy.authorization).toString('base64'));\n }\n }\n\n log.trace({\n destination: requestUrl,\n proxy: 'http://' + proxy.hostname + ':' + proxy.port,\n requestId: currentRequestId,\n }, 'proxying request');\n\n request.on('error', (error) => {\n log.error({\n error: serializeError(error),\n }, 'request error');\n });\n\n request.once('response', (response) => {\n log.trace({\n headers: response.headers,\n requestId: currentRequestId,\n statusCode: response.statusCode,\n }, 'proxying response');\n });\n\n request.shouldKeepAlive = false;\n\n const connectionConfiguration = {\n host: configuration.hostname || configuration.host,\n port: configuration.port || 80,\n proxy,\n tls: {},\n };\n\n // add optional tls options for https requests.\n // @see https://nodejs.org/docs/latest-v12.x/api/https.html#https_https_request_url_options_callback :\n // > The following additional options from tls.connect()\n // > - https://nodejs.org/docs/latest-v12.x/api/tls.html#tls_tls_connect_options_callback -\n // > are also accepted:\n // > ca, cert, ciphers, clientCertEngine, crl, dhparam, ecdhCurve, honorCipherOrder,\n // > key, passphrase, pfx, rejectUnauthorized, secureOptions, secureProtocol, servername, sessionIdContext.\n if (this.protocol === 'https:') {\n connectionConfiguration.tls = {\n ca: configuration.ca,\n cert: configuration.cert,\n ciphers: configuration.ciphers,\n clientCertEngine: configuration.clientCertEngine,\n crl: configuration.crl,\n dhparam: configuration.dhparam,\n ecdhCurve: configuration.ecdhCurve,\n honorCipherOrder: configuration.honorCipherOrder,\n key: configuration.key,\n passphrase: configuration.passphrase,\n pfx: configuration.pfx,\n rejectUnauthorized: configuration.rejectUnauthorized,\n secureOptions: configuration.secureOptions,\n secureProtocol: configuration.secureProtocol,\n servername: configuration.servername || connectionConfiguration.host,\n sessionIdContext: configuration.sessionIdContext,\n };\n\n // This is not ideal because there is no way to override this setting using `tls` configuration if `NODE_TLS_REJECT_UNAUTHORIZED=0`.\n // However, popular HTTP clients (such as https://github.com/sindresorhus/got) come with pre-configured value for `rejectUnauthorized`,\n // which makes it impossible to override that value globally and respect `rejectUnauthorized` for specific requests only.\n //\n // eslint-disable-next-line no-process-env\n if (typeof process.env.NODE_TLS_REJECT_UNAUTHORIZED === 'string' && boolean(process.env.NODE_TLS_REJECT_UNAUTHORIZED) === false) {\n connectionConfiguration.tls.rejectUnauthorized = false;\n }\n }\n\n // $FlowFixMe It appears that Flow is missing the method description.\n this.createConnection(connectionConfiguration, (error, socket) => {\n log.trace({\n target: connectionConfiguration,\n }, 'connecting');\n\n // @see https://github.com/nodejs/node/issues/5757#issuecomment-305969057\n if (socket) {\n socket.setTimeout(this.socketConnectionTimeout, () => {\n socket.destroy();\n });\n\n socket.once('connect', () => {\n log.trace({\n target: connectionConfiguration,\n }, 'connected');\n\n socket.setTimeout(0);\n });\n\n socket.once('secureConnect', () => {\n log.trace({\n target: connectionConfiguration,\n }, 'connected (secure)');\n\n socket.setTimeout(0);\n });\n }\n\n if (error) {\n request.emit('error', error);\n } else {\n log.debug('created socket');\n\n socket.on('error', (socketError) => {\n log.error({\n error: serializeError(socketError),\n }, 'socket error');\n });\n\n request.onSocket(socket);\n }\n });\n }\n}\n\nexport default Agent;\n"],"file":"Agent.js"}
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _net = _interopRequireDefault(require("net"));
9
-
10
- var _Agent = _interopRequireDefault(require("./Agent"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- class HttpProxyAgent extends _Agent.default {
15
- // @see https://github.com/sindresorhus/eslint-plugin-unicorn/issues/169#issuecomment-486980290
16
- // eslint-disable-next-line unicorn/prevent-abbreviations
17
- constructor(...args) {
18
- super(...args);
19
- this.protocol = 'http:';
20
- this.defaultPort = 80;
21
- }
22
-
23
- createConnection(configuration, callback) {
24
- const socket = _net.default.connect(configuration.proxy.port, configuration.proxy.hostname);
25
-
26
- callback(null, socket);
27
- }
28
-
29
- }
30
-
31
- var _default = HttpProxyAgent;
32
- exports.default = _default;
33
- //# sourceMappingURL=HttpProxyAgent.js.map
@@ -1,30 +0,0 @@
1
- // @flow
2
-
3
- import net from 'net';
4
- import type {
5
- ConnectionCallbackType,
6
- ConnectionConfigurationType,
7
- } from '../types';
8
- import Agent from './Agent';
9
-
10
- class HttpProxyAgent extends Agent {
11
- // @see https://github.com/sindresorhus/eslint-plugin-unicorn/issues/169#issuecomment-486980290
12
- // eslint-disable-next-line unicorn/prevent-abbreviations
13
- constructor (...args: *) {
14
- super(...args);
15
-
16
- this.protocol = 'http:';
17
- this.defaultPort = 80;
18
- }
19
-
20
- createConnection (configuration: ConnectionConfigurationType, callback: ConnectionCallbackType) {
21
- const socket = net.connect(
22
- configuration.proxy.port,
23
- configuration.proxy.hostname,
24
- );
25
-
26
- callback(null, socket);
27
- }
28
- }
29
-
30
- export default HttpProxyAgent;
@@ -1 +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"}
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _net = _interopRequireDefault(require("net"));
9
-
10
- var _tls = _interopRequireDefault(require("tls"));
11
-
12
- var _Agent = _interopRequireDefault(require("./Agent"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- class HttpsProxyAgent extends _Agent.default {
17
- // eslint-disable-next-line unicorn/prevent-abbreviations
18
- constructor(...args) {
19
- super(...args);
20
- this.protocol = 'https:';
21
- this.defaultPort = 443;
22
- }
23
-
24
- createConnection(configuration, callback) {
25
- const socket = _net.default.connect(configuration.proxy.port, configuration.proxy.hostname);
26
-
27
- socket.on('error', error => {
28
- callback(error);
29
- });
30
- socket.once('data', () => {
31
- const secureSocket = _tls.default.connect({ ...configuration.tls,
32
- socket
33
- });
34
-
35
- callback(null, secureSocket);
36
- });
37
- let connectMessage = '';
38
- connectMessage += 'CONNECT ' + configuration.host + ':' + configuration.port + ' HTTP/1.1\r\n';
39
- connectMessage += 'Host: ' + configuration.host + ':' + configuration.port + '\r\n';
40
-
41
- if (configuration.proxy.authorization) {
42
- connectMessage += 'Proxy-Authorization: Basic ' + Buffer.from(configuration.proxy.authorization).toString('base64') + '\r\n';
43
- }
44
-
45
- connectMessage += '\r\n';
46
- socket.write(connectMessage);
47
- }
48
-
49
- }
50
-
51
- var _default = HttpsProxyAgent;
52
- exports.default = _default;
53
- //# sourceMappingURL=HttpsProxyAgent.js.map
@@ -1,54 +0,0 @@
1
- // @flow
2
-
3
- import net from 'net';
4
- import tls from 'tls';
5
- import type {
6
- ConnectionCallbackType,
7
- ConnectionConfigurationType,
8
- } from '../types';
9
- import Agent from './Agent';
10
-
11
- class HttpsProxyAgent extends Agent {
12
- // eslint-disable-next-line unicorn/prevent-abbreviations
13
- constructor (...args: *) {
14
- super(...args);
15
-
16
- this.protocol = 'https:';
17
- this.defaultPort = 443;
18
- }
19
-
20
- createConnection (configuration: ConnectionConfigurationType, callback: ConnectionCallbackType) {
21
- const socket = net.connect(
22
- configuration.proxy.port,
23
- configuration.proxy.hostname,
24
- );
25
-
26
- socket.on('error', (error) => {
27
- callback(error);
28
- });
29
-
30
- socket.once('data', () => {
31
- const secureSocket = tls.connect({
32
- ...configuration.tls,
33
- socket,
34
- });
35
-
36
- callback(null, secureSocket);
37
- });
38
-
39
- let connectMessage = '';
40
-
41
- connectMessage += 'CONNECT ' + configuration.host + ':' + configuration.port + ' HTTP/1.1\r\n';
42
- connectMessage += 'Host: ' + configuration.host + ':' + configuration.port + '\r\n';
43
-
44
- if (configuration.proxy.authorization) {
45
- connectMessage += 'Proxy-Authorization: Basic ' + Buffer.from(configuration.proxy.authorization).toString('base64') + '\r\n';
46
- }
47
-
48
- connectMessage += '\r\n';
49
-
50
- socket.write(connectMessage);
51
- }
52
- }
53
-
54
- export default HttpsProxyAgent;
@@ -1 +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"}
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "Agent", {
7
- enumerable: true,
8
- get: function () {
9
- return _Agent.default;
10
- }
11
- });
12
- Object.defineProperty(exports, "HttpProxyAgent", {
13
- enumerable: true,
14
- get: function () {
15
- return _HttpProxyAgent.default;
16
- }
17
- });
18
- Object.defineProperty(exports, "HttpsProxyAgent", {
19
- enumerable: true,
20
- get: function () {
21
- return _HttpsProxyAgent.default;
22
- }
23
- });
24
-
25
- var _Agent = _interopRequireDefault(require("./Agent"));
26
-
27
- var _HttpProxyAgent = _interopRequireDefault(require("./HttpProxyAgent"));
28
-
29
- var _HttpsProxyAgent = _interopRequireDefault(require("./HttpsProxyAgent"));
30
-
31
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
32
- //# sourceMappingURL=index.js.map
@@ -1,5 +0,0 @@
1
- // @flow
2
-
3
- export {default as Agent} from './Agent';
4
- export {default as HttpProxyAgent} from './HttpProxyAgent';
5
- export {default as HttpsProxyAgent} from './HttpsProxyAgent';
@@ -1 +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"}
package/dist/errors.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.UnexpectedStateError = void 0;
7
-
8
- var _es6Error = _interopRequireDefault(require("es6-error"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /* eslint-disable fp/no-class, fp/no-this */
13
- class UnexpectedStateError extends _es6Error.default {
14
- constructor(message, code = 'UNEXPECTED_STATE_ERROR') {
15
- super(message);
16
- this.code = code;
17
- }
18
-
19
- }
20
-
21
- exports.UnexpectedStateError = UnexpectedStateError;
22
- //# sourceMappingURL=errors.js.map