global-agent 2.2.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 -57
  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
@@ -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/dist/types.js.map DELETED
@@ -1 +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"}
@@ -1,62 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _http = _interopRequireDefault(require("http"));
9
-
10
- var _https = _interopRequireDefault(require("https"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- // eslint-disable-next-line flowtype/no-weak-types
15
- const bindHttpMethod = (originalMethod, agent, forceGlobalAgent) => {
16
- // eslint-disable-next-line unicorn/prevent-abbreviations
17
- return (...args) => {
18
- let url;
19
- let options;
20
- let callback;
21
-
22
- if (typeof args[0] === 'string' || args[0] instanceof URL) {
23
- url = args[0];
24
-
25
- if (typeof args[1] === 'function') {
26
- options = {};
27
- callback = args[1];
28
- } else {
29
- options = { ...args[1]
30
- };
31
- callback = args[2];
32
- }
33
- } else {
34
- options = { ...args[0]
35
- };
36
- callback = args[1];
37
- }
38
-
39
- if (forceGlobalAgent) {
40
- options.agent = agent;
41
- } else {
42
- if (!options.agent) {
43
- options.agent = agent;
44
- }
45
-
46
- if (options.agent === _http.default.globalAgent || options.agent === _https.default.globalAgent) {
47
- options.agent = agent;
48
- }
49
- }
50
-
51
- if (url) {
52
- // $FlowFixMe
53
- return originalMethod(url, options, callback);
54
- } else {
55
- return originalMethod(options, callback);
56
- }
57
- };
58
- };
59
-
60
- var _default = bindHttpMethod;
61
- exports.default = _default;
62
- //# sourceMappingURL=bindHttpMethod.js.map
@@ -1,54 +0,0 @@
1
- // @flow
2
-
3
- import http from 'http';
4
- import https from 'https';
5
-
6
- type AgentType = http.Agent | https.Agent;
7
-
8
- // eslint-disable-next-line flowtype/no-weak-types
9
- export default (originalMethod: Function, agent: AgentType, forceGlobalAgent: boolean) => {
10
- // eslint-disable-next-line unicorn/prevent-abbreviations
11
- return (...args: *) => {
12
- let url;
13
- let options;
14
- let callback;
15
-
16
- if (typeof args[0] === 'string' || args[0] instanceof URL) {
17
- url = args[0];
18
-
19
- if (typeof args[1] === 'function') {
20
- options = {};
21
- callback = args[1];
22
- } else {
23
- options = {
24
- ...args[1],
25
- };
26
- callback = args[2];
27
- }
28
- } else {
29
- options = {
30
- ...args[0],
31
- };
32
- callback = args[1];
33
- }
34
-
35
- if (forceGlobalAgent) {
36
- options.agent = agent;
37
- } else {
38
- if (!options.agent) {
39
- options.agent = agent;
40
- }
41
-
42
- if (options.agent === http.globalAgent || options.agent === https.globalAgent) {
43
- options.agent = agent;
44
- }
45
- }
46
-
47
- if (url) {
48
- // $FlowFixMe
49
- return originalMethod(url, options, callback);
50
- } else {
51
- return originalMethod(options, callback);
52
- }
53
- };
54
- };
@@ -1 +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"}
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "bindHttpMethod", {
7
- enumerable: true,
8
- get: function () {
9
- return _bindHttpMethod.default;
10
- }
11
- });
12
- Object.defineProperty(exports, "isUrlMatchingNoProxy", {
13
- enumerable: true,
14
- get: function () {
15
- return _isUrlMatchingNoProxy.default;
16
- }
17
- });
18
- Object.defineProperty(exports, "parseProxyUrl", {
19
- enumerable: true,
20
- get: function () {
21
- return _parseProxyUrl.default;
22
- }
23
- });
24
-
25
- var _bindHttpMethod = _interopRequireDefault(require("./bindHttpMethod"));
26
-
27
- var _isUrlMatchingNoProxy = _interopRequireDefault(require("./isUrlMatchingNoProxy"));
28
-
29
- var _parseProxyUrl = _interopRequireDefault(require("./parseProxyUrl"));
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 bindHttpMethod} from './bindHttpMethod';
4
- export {default as isUrlMatchingNoProxy} from './isUrlMatchingNoProxy';
5
- export {default as parseProxyUrl} from './parseProxyUrl';
@@ -1 +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"}
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _url = require("url");
9
-
10
- var _matcher = _interopRequireDefault(require("matcher"));
11
-
12
- var _errors = require("../errors");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const isUrlMatchingNoProxy = (subjectUrl, noProxy) => {
17
- const subjectUrlTokens = (0, _url.parse)(subjectUrl);
18
- const rules = noProxy.split(/[\s,]+/);
19
-
20
- for (const rule of rules) {
21
- const ruleMatch = rule.replace(/^(?<leadingDot>\.)/, '*').match(/^(?<hostname>.+?)(?::(?<port>\d+))?$/);
22
-
23
- if (!ruleMatch || !ruleMatch.groups) {
24
- throw new _errors.UnexpectedStateError('Invalid NO_PROXY pattern.');
25
- }
26
-
27
- if (!ruleMatch.groups.hostname) {
28
- throw new _errors.UnexpectedStateError('NO_PROXY entry pattern must include hostname. Use * to match any hostname.');
29
- }
30
-
31
- const hostnameIsMatch = _matcher.default.isMatch(subjectUrlTokens.hostname, ruleMatch.groups.hostname);
32
-
33
- if (hostnameIsMatch && (!ruleMatch.groups || !ruleMatch.groups.port || subjectUrlTokens.port && subjectUrlTokens.port === ruleMatch.groups.port)) {
34
- return true;
35
- }
36
- }
37
-
38
- return false;
39
- };
40
-
41
- var _default = isUrlMatchingNoProxy;
42
- exports.default = _default;
43
- //# sourceMappingURL=isUrlMatchingNoProxy.js.map
@@ -1 +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,QAAd,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"}
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _url = require("url");
9
-
10
- var _errors = require("../errors");
11
-
12
- const parseProxyUrl = url => {
13
- const urlTokens = (0, _url.parse)(url);
14
-
15
- if (urlTokens.query !== null) {
16
- throw new _errors.UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');
17
- }
18
-
19
- if (urlTokens.hash !== null) {
20
- throw new _errors.UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');
21
- }
22
-
23
- if (urlTokens.protocol !== 'http:') {
24
- throw new _errors.UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be "http:".');
25
- }
26
-
27
- let port = 80;
28
-
29
- if (urlTokens.port) {
30
- port = Number.parseInt(urlTokens.port, 10);
31
- }
32
-
33
- return {
34
- authorization: urlTokens.auth || null,
35
- hostname: urlTokens.hostname,
36
- port
37
- };
38
- };
39
-
40
- var _default = parseProxyUrl;
41
- exports.default = _default;
42
- //# sourceMappingURL=parseProxyUrl.js.map
@@ -1,36 +0,0 @@
1
- // @flow
2
-
3
- import {
4
- parse as parseUrl,
5
- } from 'url';
6
- import {
7
- UnexpectedStateError,
8
- } from '../errors';
9
-
10
- export default (url: string) => {
11
- const urlTokens = parseUrl(url);
12
-
13
- if (urlTokens.query !== null) {
14
- throw new UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');
15
- }
16
-
17
- if (urlTokens.hash !== null) {
18
- throw new UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');
19
- }
20
-
21
- if (urlTokens.protocol !== 'http:') {
22
- throw new UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be "http:".');
23
- }
24
-
25
- let port = 80;
26
-
27
- if (urlTokens.port) {
28
- port = Number.parseInt(urlTokens.port, 10);
29
- }
30
-
31
- return {
32
- authorization: urlTokens.auth || null,
33
- hostname: urlTokens.hostname,
34
- port,
35
- };
36
- };
@@ -1 +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"}
@@ -1,212 +0,0 @@
1
- // @flow
2
-
3
- import {
4
- serializeError,
5
- } from 'serialize-error';
6
- import {
7
- boolean,
8
- } from 'boolean';
9
- import Logger from '../Logger';
10
- import type {
11
- AgentType,
12
- GetUrlProxyMethodType,
13
- IsProxyConfiguredMethodType,
14
- MustUrlUseProxyMethodType,
15
- ProtocolType,
16
- } from '../types';
17
-
18
- const log = Logger.child({
19
- namespace: 'Agent',
20
- });
21
-
22
- let requestId = 0;
23
-
24
- class Agent {
25
- defaultPort: number;
26
-
27
- protocol: ProtocolType;
28
-
29
- fallbackAgent: AgentType;
30
-
31
- isProxyConfigured: IsProxyConfiguredMethodType;
32
-
33
- mustUrlUseProxy: MustUrlUseProxyMethodType;
34
-
35
- getUrlProxy: GetUrlProxyMethodType;
36
-
37
- socketConnectionTimeout: number;
38
-
39
- constructor (
40
- isProxyConfigured: IsProxyConfiguredMethodType,
41
- mustUrlUseProxy: MustUrlUseProxyMethodType,
42
- getUrlProxy: GetUrlProxyMethodType,
43
- fallbackAgent: AgentType,
44
- socketConnectionTimeout: number,
45
- ) {
46
- this.fallbackAgent = fallbackAgent;
47
- this.isProxyConfigured = isProxyConfigured;
48
- this.mustUrlUseProxy = mustUrlUseProxy;
49
- this.getUrlProxy = getUrlProxy;
50
- this.socketConnectionTimeout = socketConnectionTimeout;
51
- }
52
-
53
- addRequest (request: *, configuration: *) {
54
- let requestUrl;
55
-
56
- // It is possible that addRequest was constructed for a proxied request already, e.g.
57
- // "request" package does this when it detects that a proxy should be used
58
- // https://github.com/request/request/blob/212570b6971a732b8dd9f3c73354bcdda158a737/request.js#L402
59
- // https://gist.github.com/gajus/e2074cd3b747864ffeaabbd530d30218
60
- if (request.path.startsWith('http://') || request.path.startsWith('https://')) {
61
- requestUrl = request.path;
62
- } else {
63
- requestUrl = this.protocol + '//' + (configuration.hostname || configuration.host) + (configuration.port === 80 || configuration.port === 443 ? '' : ':' + configuration.port) + request.path;
64
- }
65
-
66
- if (!this.isProxyConfigured()) {
67
- log.trace({
68
- destination: requestUrl,
69
- }, 'not proxying request; GLOBAL_AGENT.HTTP_PROXY is not configured');
70
-
71
- // $FlowFixMe It appears that Flow is missing the method description.
72
- this.fallbackAgent.addRequest(request, configuration);
73
-
74
- return;
75
- }
76
-
77
- if (!this.mustUrlUseProxy(requestUrl)) {
78
- log.trace({
79
- destination: requestUrl,
80
- }, 'not proxying request; url matches GLOBAL_AGENT.NO_PROXY');
81
-
82
- // $FlowFixMe It appears that Flow is missing the method description.
83
- this.fallbackAgent.addRequest(request, configuration);
84
-
85
- return;
86
- }
87
-
88
- const currentRequestId = requestId++;
89
-
90
- const proxy = this.getUrlProxy(requestUrl);
91
-
92
- if (this.protocol === 'http:') {
93
- request.path = requestUrl;
94
-
95
- if (proxy.authorization) {
96
- request.setHeader('proxy-authorization', 'Basic ' + Buffer.from(proxy.authorization).toString('base64'));
97
- }
98
- }
99
-
100
- log.trace({
101
- destination: requestUrl,
102
- proxy: 'http://' + proxy.hostname + ':' + proxy.port,
103
- requestId: currentRequestId,
104
- }, 'proxying request');
105
-
106
- request.on('error', (error) => {
107
- log.error({
108
- error: serializeError(error),
109
- }, 'request error');
110
- });
111
-
112
- request.once('response', (response) => {
113
- log.trace({
114
- headers: response.headers,
115
- requestId: currentRequestId,
116
- statusCode: response.statusCode,
117
- }, 'proxying response');
118
- });
119
-
120
- request.shouldKeepAlive = false;
121
-
122
- const connectionConfiguration = {
123
- host: configuration.hostname || configuration.host,
124
- port: configuration.port || 80,
125
- proxy,
126
- tls: {},
127
- };
128
-
129
- // add optional tls options for https requests.
130
- // @see https://nodejs.org/docs/latest-v12.x/api/https.html#https_https_request_url_options_callback :
131
- // > The following additional options from tls.connect()
132
- // > - https://nodejs.org/docs/latest-v12.x/api/tls.html#tls_tls_connect_options_callback -
133
- // > are also accepted:
134
- // > ca, cert, ciphers, clientCertEngine, crl, dhparam, ecdhCurve, honorCipherOrder,
135
- // > key, passphrase, pfx, rejectUnauthorized, secureOptions, secureProtocol, servername, sessionIdContext.
136
- if (this.protocol === 'https:') {
137
- connectionConfiguration.tls = {
138
- ca: configuration.ca,
139
- cert: configuration.cert,
140
- ciphers: configuration.ciphers,
141
- clientCertEngine: configuration.clientCertEngine,
142
- crl: configuration.crl,
143
- dhparam: configuration.dhparam,
144
- ecdhCurve: configuration.ecdhCurve,
145
- honorCipherOrder: configuration.honorCipherOrder,
146
- key: configuration.key,
147
- passphrase: configuration.passphrase,
148
- pfx: configuration.pfx,
149
- rejectUnauthorized: configuration.rejectUnauthorized,
150
- secureOptions: configuration.secureOptions,
151
- secureProtocol: configuration.secureProtocol,
152
- servername: configuration.servername || connectionConfiguration.host,
153
- sessionIdContext: configuration.sessionIdContext,
154
- };
155
-
156
- // This is not ideal because there is no way to override this setting using `tls` configuration if `NODE_TLS_REJECT_UNAUTHORIZED=0`.
157
- // However, popular HTTP clients (such as https://github.com/sindresorhus/got) come with pre-configured value for `rejectUnauthorized`,
158
- // which makes it impossible to override that value globally and respect `rejectUnauthorized` for specific requests only.
159
- //
160
- // eslint-disable-next-line no-process-env
161
- if (typeof process.env.NODE_TLS_REJECT_UNAUTHORIZED === 'string' && boolean(process.env.NODE_TLS_REJECT_UNAUTHORIZED) === false) {
162
- connectionConfiguration.tls.rejectUnauthorized = false;
163
- }
164
- }
165
-
166
- // $FlowFixMe It appears that Flow is missing the method description.
167
- this.createConnection(connectionConfiguration, (error, socket) => {
168
- log.trace({
169
- target: connectionConfiguration,
170
- }, 'connecting');
171
-
172
- // @see https://github.com/nodejs/node/issues/5757#issuecomment-305969057
173
- if (socket) {
174
- socket.setTimeout(this.socketConnectionTimeout, () => {
175
- socket.destroy();
176
- });
177
-
178
- socket.once('connect', () => {
179
- log.trace({
180
- target: connectionConfiguration,
181
- }, 'connected');
182
-
183
- socket.setTimeout(0);
184
- });
185
-
186
- socket.once('secureConnect', () => {
187
- log.trace({
188
- target: connectionConfiguration,
189
- }, 'connected (secure)');
190
-
191
- socket.setTimeout(0);
192
- });
193
- }
194
-
195
- if (error) {
196
- request.emit('error', error);
197
- } else {
198
- log.debug('created socket');
199
-
200
- socket.on('error', (socketError) => {
201
- log.error({
202
- error: serializeError(socketError),
203
- }, 'socket error');
204
- });
205
-
206
- request.onSocket(socket);
207
- }
208
- });
209
- }
210
- }
211
-
212
- export default Agent;
@@ -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,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,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';