@airgap/coinlib-core 0.13.46 → 0.13.47

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 (124) hide show
  1. package/dependencies/src/axios-0.33.0/index.d.ts +345 -0
  2. package/dependencies/src/axios-0.33.0/lib/adapters/http.js +771 -0
  3. package/dependencies/src/axios-0.33.0/lib/adapters/xhr.js +305 -0
  4. package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/axios.js +22 -7
  5. package/dependencies/src/axios-0.33.0/lib/cancel/CancelToken.js +118 -0
  6. package/dependencies/src/axios-0.33.0/lib/cancel/CanceledError.js +24 -0
  7. package/dependencies/src/axios-0.33.0/lib/core/Axios.js +178 -0
  8. package/dependencies/src/axios-0.33.0/lib/core/AxiosError.js +173 -0
  9. package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/core/InterceptorManager.js +13 -2
  10. package/dependencies/src/axios-0.33.0/lib/core/buildFullPath.js +23 -0
  11. package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/core/dispatchRequest.js +34 -16
  12. package/dependencies/src/axios-0.33.0/lib/core/mergeConfig.js +117 -0
  13. package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/core/settle.js +4 -4
  14. package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/core/transformData.js +5 -2
  15. package/dependencies/src/axios-0.33.0/lib/defaults/index.js +181 -0
  16. package/dependencies/src/axios-0.33.0/lib/defaults/transitional.js +7 -0
  17. package/dependencies/src/axios-0.33.0/lib/env/classes/FormData.js +2 -0
  18. package/dependencies/src/axios-0.33.0/lib/env/data.js +3 -0
  19. package/dependencies/src/axios-0.33.0/lib/helpers/AxiosURLSearchParams.js +50 -0
  20. package/dependencies/src/axios-0.33.0/lib/helpers/bind.js +7 -0
  21. package/dependencies/src/axios-0.33.0/lib/helpers/buildURL.js +63 -0
  22. package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/combineURLs.js +1 -1
  23. package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/cookies.js +15 -2
  24. package/dependencies/src/axios-0.33.0/lib/helpers/defaultRedactKeys.js +3 -0
  25. package/dependencies/src/axios-0.33.0/lib/helpers/estimateDataURLDecodedBytes.js +79 -0
  26. package/dependencies/src/axios-0.33.0/lib/helpers/formDataToJSON.js +91 -0
  27. package/dependencies/src/axios-0.33.0/lib/helpers/fromDataURI.js +51 -0
  28. package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/isAbsoluteURL.js +1 -1
  29. package/dependencies/src/axios-0.33.0/lib/helpers/isAxiosError.js +13 -0
  30. package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/isURLSameOrigin.js +12 -12
  31. package/dependencies/src/axios-0.33.0/lib/helpers/null.js +2 -0
  32. package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/parseHeaders.js +2 -2
  33. package/dependencies/src/axios-0.33.0/lib/helpers/parseProtocol.js +6 -0
  34. package/dependencies/src/axios-0.33.0/lib/helpers/sanitizeHeaderValue.js +22 -0
  35. package/dependencies/src/axios-0.33.0/lib/helpers/shouldBypassProxy.js +187 -0
  36. package/dependencies/src/axios-0.33.0/lib/helpers/toFormData.js +212 -0
  37. package/dependencies/src/axios-0.33.0/lib/helpers/toURLEncodedForm.js +18 -0
  38. package/dependencies/src/axios-0.33.0/lib/helpers/validator.js +86 -0
  39. package/dependencies/src/axios-0.33.0/lib/platform/browser/classes/FormData.js +3 -0
  40. package/dependencies/src/axios-0.33.0/lib/platform/browser/classes/URLSearchParams.js +5 -0
  41. package/dependencies/src/axios-0.33.0/lib/platform/browser/index.js +11 -0
  42. package/dependencies/src/axios-0.33.0/lib/platform/index.js +3 -0
  43. package/dependencies/src/axios-0.33.0/lib/platform/node/classes/FormData.js +3 -0
  44. package/dependencies/src/axios-0.33.0/lib/platform/node/classes/URLSearchParams.js +5 -0
  45. package/dependencies/src/axios-0.33.0/lib/platform/node/index.js +11 -0
  46. package/dependencies/src/axios-0.33.0/lib/utils.js +565 -0
  47. package/dependencies/src/axios-0.33.0/package.json +100 -0
  48. package/dependencies/src/{bn.js-4.11.8 → bn.js-4.11.9}/lib/bn.js +7 -1
  49. package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/curve/base.js +36 -31
  50. package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic/curve/edwards.js +13 -10
  51. package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/curve/mont.js +1 -1
  52. package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic/curve/short.js +48 -47
  53. package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/curves.js +21 -21
  54. package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic/ec/index.js +53 -16
  55. package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/ec/key.js +8 -5
  56. package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/ec/signature.js +11 -1
  57. package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/eddsa/index.js +5 -2
  58. package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/eddsa/signature.js +3 -2
  59. package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic/precomputed/secp256k1.js +197 -197
  60. package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/utils.js +12 -9
  61. package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/package.json +20 -22
  62. package/dependencies/src/ethereumjs-util-5.2.0/index.js +1 -1
  63. package/dependencies/src/follow-redirects-1.16.0/debug.js +15 -0
  64. package/dependencies/src/follow-redirects-1.16.0/index.js +709 -0
  65. package/dependencies/src/follow-redirects-1.16.0/package.json +58 -0
  66. package/dependencies/src/proxy-from-env-1.1.0/index.js +108 -0
  67. package/dependencies/src/proxy-from-env-1.1.0/package.json +34 -0
  68. package/dependencies/src/secp256k1-3.7.1/lib/elliptic/index.js +2 -2
  69. package/dependencies/src/secp256k1-4.0.2/lib/elliptic.js +1 -1
  70. package/dependencies/src/tiny-secp256k1-1.1.3/js.js +2 -2
  71. package/errors/index.d.ts +2 -2
  72. package/errors/index.js.map +1 -1
  73. package/package.json +2 -2
  74. package/utils/remote-data/HttpRemoteData.js +3 -8
  75. package/utils/remote-data/HttpRemoteData.js.map +1 -1
  76. package/utils/remote-data/IpfsRemoteData.js +13 -7
  77. package/utils/remote-data/IpfsRemoteData.js.map +1 -1
  78. package/utils/remote-data/Sha256RemoteData.js +5 -6
  79. package/utils/remote-data/Sha256RemoteData.js.map +1 -1
  80. package/utils/remote-data/remoteDataRequest.d.ts +16 -0
  81. package/utils/remote-data/remoteDataRequest.js +240 -0
  82. package/utils/remote-data/remoteDataRequest.js.map +1 -0
  83. package/dependencies/src/axios-0.19.0/index.d.ts +0 -152
  84. package/dependencies/src/axios-0.19.0/lib/adapters/http.js +0 -275
  85. package/dependencies/src/axios-0.19.0/lib/adapters/xhr.js +0 -174
  86. package/dependencies/src/axios-0.19.0/lib/cancel/Cancel.js +0 -19
  87. package/dependencies/src/axios-0.19.0/lib/cancel/CancelToken.js +0 -57
  88. package/dependencies/src/axios-0.19.0/lib/core/Axios.js +0 -86
  89. package/dependencies/src/axios-0.19.0/lib/core/createError.js +0 -18
  90. package/dependencies/src/axios-0.19.0/lib/core/enhanceError.js +0 -42
  91. package/dependencies/src/axios-0.19.0/lib/core/mergeConfig.js +0 -51
  92. package/dependencies/src/axios-0.19.0/lib/defaults.js +0 -98
  93. package/dependencies/src/axios-0.19.0/lib/helpers/bind.js +0 -11
  94. package/dependencies/src/axios-0.19.0/lib/helpers/buildURL.js +0 -71
  95. package/dependencies/src/axios-0.19.0/lib/utils.js +0 -334
  96. package/dependencies/src/axios-0.19.0/package.json +0 -85
  97. package/dependencies/src/elliptic-6.5.1/lib/elliptic/curve/base.js +0 -374
  98. package/dependencies/src/elliptic-6.5.1/lib/elliptic/curve/mont.js +0 -178
  99. package/dependencies/src/elliptic-6.5.1/lib/elliptic/curves.js +0 -206
  100. package/dependencies/src/elliptic-6.5.1/lib/elliptic/ec/key.js +0 -118
  101. package/dependencies/src/elliptic-6.5.1/lib/elliptic/ec/signature.js +0 -134
  102. package/dependencies/src/elliptic-6.5.1/lib/elliptic/eddsa/index.js +0 -118
  103. package/dependencies/src/elliptic-6.5.1/lib/elliptic/eddsa/signature.js +0 -65
  104. package/dependencies/src/elliptic-6.5.1/lib/elliptic/utils.js +0 -120
  105. package/dependencies/src/elliptic-6.5.3/lib/elliptic/curve/edwards.js +0 -432
  106. package/dependencies/src/elliptic-6.5.3/lib/elliptic/curve/index.js +0 -8
  107. package/dependencies/src/elliptic-6.5.3/lib/elliptic/curve/short.js +0 -937
  108. package/dependencies/src/elliptic-6.5.3/lib/elliptic/ec/index.js +0 -241
  109. package/dependencies/src/elliptic-6.5.3/lib/elliptic/eddsa/key.js +0 -95
  110. package/dependencies/src/elliptic-6.5.3/lib/elliptic/precomputed/secp256k1.js +0 -780
  111. package/dependencies/src/elliptic-6.5.3/lib/elliptic.js +0 -13
  112. package/dependencies/src/elliptic-6.5.3/package.json +0 -55
  113. package/dependencies/src/follow-redirects-1.5.10/index.js +0 -322
  114. package/dependencies/src/is-buffer-2.0.3/index.js +0 -11
  115. /package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/index.js +0 -0
  116. /package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/cancel/isCancel.js +0 -0
  117. /package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/deprecatedMethod.js +0 -0
  118. /package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/normalizeHeaderName.js +0 -0
  119. /package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/spread.js +0 -0
  120. /package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic/curve/index.js +0 -0
  121. /package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic/eddsa/key.js +0 -0
  122. /package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic.js +0 -0
  123. /package/dependencies/src/{follow-redirects-1.5.10 → follow-redirects-1.16.0}/http.js +0 -0
  124. /package/dependencies/src/{follow-redirects-1.5.10 → follow-redirects-1.16.0}/https.js +0 -0
@@ -0,0 +1,771 @@
1
+ 'use strict';
2
+
3
+ var utils = require('./../utils');
4
+ var settle = require('./../core/settle');
5
+ var buildFullPath = require('../core/buildFullPath');
6
+ var buildURL = require('./../helpers/buildURL');
7
+ var getProxyForUrl = require('../../../proxy-from-env-1.1.0/index').getProxyForUrl;
8
+ var http = require('http');
9
+ var https = require('https');
10
+ var httpFollow = require('../../../follow-redirects-1.16.0/index').http;
11
+ var httpsFollow = require('../../../follow-redirects-1.16.0/index').https;
12
+ var url = require('url');
13
+ var path = require('path');
14
+ var zlib = require('zlib');
15
+ var VERSION = require('./../env/data').version;
16
+ var transitionalDefaults = require('../defaults/transitional');
17
+ var AxiosError = require('../core/AxiosError');
18
+ var CanceledError = require('../cancel/CanceledError');
19
+ var platform = require('../platform');
20
+ var fromDataURI = require('../helpers/fromDataURI');
21
+ var stream = require('stream');
22
+ var estimateDataURLDecodedBytes = require('../helpers/estimateDataURLDecodedBytes.js');
23
+ var shouldBypassProxy = require('../helpers/shouldBypassProxy');
24
+
25
+ var isHttps = /https:?/;
26
+
27
+ var supportedProtocols = platform.protocols.map(function(protocol) {
28
+ return protocol + ':';
29
+ });
30
+
31
+ function dispatchBeforeRedirect(options) {
32
+ if (options.beforeRedirects.proxy) {
33
+ options.beforeRedirects.proxy(options);
34
+ }
35
+ if (options.beforeRedirects.config) {
36
+ options.beforeRedirects.config(options);
37
+ }
38
+ }
39
+
40
+ function removeProxyAuthorization(headers) {
41
+ Object.keys(headers).forEach(function removeHeader(header) {
42
+ if (header.toLowerCase() === 'proxy-authorization') {
43
+ delete headers[header];
44
+ }
45
+ });
46
+ }
47
+
48
+ function normalizeSocketPath(socketPath) {
49
+ if (/^\\\\[.?]\\pipe\\/i.test(socketPath)) {
50
+ return socketPath;
51
+ }
52
+
53
+ return path.resolve(socketPath);
54
+ }
55
+
56
+ function getAllowedSocketPaths(config) {
57
+ var allowedSocketPaths = config.allowedSocketPaths;
58
+
59
+ if (
60
+ allowedSocketPaths === null ||
61
+ typeof allowedSocketPaths === 'undefined'
62
+ ) {
63
+ return null;
64
+ }
65
+
66
+ if (utils.isString(allowedSocketPaths)) {
67
+ return [allowedSocketPaths];
68
+ }
69
+
70
+ if (utils.isArray(allowedSocketPaths)) {
71
+ for (var i = 0; i < allowedSocketPaths.length; i++) {
72
+ if (!utils.isString(allowedSocketPaths[i])) {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ return allowedSocketPaths;
78
+ }
79
+
80
+ return false;
81
+ }
82
+
83
+ function checkSocketPath(config) {
84
+ var socketPath = config.socketPath;
85
+
86
+ if (!socketPath) {
87
+ return null;
88
+ }
89
+
90
+ if (!utils.isString(socketPath)) {
91
+ return new AxiosError(
92
+ 'config.socketPath must be a string',
93
+ AxiosError.ERR_BAD_OPTION_VALUE,
94
+ config
95
+ );
96
+ }
97
+
98
+ var allowedSocketPaths = getAllowedSocketPaths(config);
99
+
100
+ if (allowedSocketPaths === false) {
101
+ return new AxiosError(
102
+ 'config.allowedSocketPaths must be a string, an array of strings, or null',
103
+ AxiosError.ERR_BAD_OPTION_VALUE,
104
+ config
105
+ );
106
+ }
107
+
108
+ if (allowedSocketPaths) {
109
+ var normalizedSocketPath = normalizeSocketPath(socketPath);
110
+ var allowed = allowedSocketPaths.some(
111
+ function isAllowed(allowedSocketPath) {
112
+ return normalizeSocketPath(allowedSocketPath) === normalizedSocketPath;
113
+ }
114
+ );
115
+
116
+ if (!allowed) {
117
+ return new AxiosError(
118
+ 'config.socketPath is not allowed by config.allowedSocketPaths',
119
+ AxiosError.ERR_BAD_OPTION_VALUE,
120
+ config
121
+ );
122
+ }
123
+ }
124
+
125
+ return null;
126
+ }
127
+
128
+ /**
129
+ *
130
+ * @param {http.ClientRequestArgs} options
131
+ * @param {AxiosProxyConfig} configProxy
132
+ * @param {string} location
133
+ */
134
+ function setProxy(options, configProxy, location) {
135
+ var proxy = configProxy;
136
+ if (!proxy && proxy !== false) {
137
+ var proxyUrl = getProxyForUrl(location);
138
+ if (proxyUrl) {
139
+ if (!shouldBypassProxy(location)) {
140
+ proxy = url.parse(proxyUrl);
141
+ // replace 'host' since the proxy object is not a URL object
142
+ proxy.host = proxy.hostname;
143
+ }
144
+ }
145
+ }
146
+ if (!proxy) {
147
+ removeProxyAuthorization(options.headers);
148
+ }
149
+ if (proxy) {
150
+ // Basic proxy authorization
151
+ var proxyAuth = utils.hasOwnProperty(proxy, 'auth')
152
+ ? proxy.auth
153
+ : undefined;
154
+ if (proxyAuth) {
155
+ // Support proxy auth object form
156
+ if (utils.isObject(proxyAuth)) {
157
+ var proxyUsername = utils.hasOwnProperty(proxyAuth, 'username')
158
+ ? proxyAuth.username
159
+ : '';
160
+ var proxyPassword = utils.hasOwnProperty(proxyAuth, 'password')
161
+ ? proxyAuth.password
162
+ : '';
163
+ proxyAuth =
164
+ proxyUsername || proxyPassword
165
+ ? proxyUsername + ':' + proxyPassword
166
+ : undefined;
167
+ }
168
+ if (proxyAuth) {
169
+ var base64 = Buffer.from(proxyAuth, 'utf8').toString('base64');
170
+ removeProxyAuthorization(options.headers);
171
+ options.headers['Proxy-Authorization'] = 'Basic ' + base64;
172
+ }
173
+ }
174
+
175
+ options.headers.host =
176
+ options.hostname + (options.port ? ':' + options.port : '');
177
+ options.hostname = proxy.host;
178
+ options.host = proxy.host;
179
+ options.port = proxy.port;
180
+ options.path = location;
181
+ if (proxy.protocol) {
182
+ options.protocol = proxy.protocol;
183
+ }
184
+ }
185
+
186
+ options.beforeRedirects.proxy = function beforeRedirect(redirectOptions) {
187
+ // Configure proxy for redirected request, passing the original config proxy to apply
188
+ // the exact same logic as if the redirected request was performed by axios directly.
189
+ setProxy(redirectOptions, configProxy, redirectOptions.href);
190
+ };
191
+ }
192
+
193
+ /*eslint consistent-return:0*/
194
+ module.exports = function httpAdapter(config) {
195
+ return new Promise(function dispatchHttpRequest(
196
+ resolvePromise,
197
+ rejectPromise
198
+ ) {
199
+ var onCanceled;
200
+ function done() {
201
+ if (config.cancelToken) {
202
+ config.cancelToken.unsubscribe(onCanceled);
203
+ }
204
+
205
+ if (config.signal) {
206
+ config.signal.removeEventListener('abort', onCanceled);
207
+ }
208
+ }
209
+ var resolve = function resolve(value) {
210
+ done();
211
+ resolvePromise(value);
212
+ };
213
+ var rejected = false;
214
+ var reject = function reject(value) {
215
+ done();
216
+ rejected = true;
217
+ rejectPromise(value);
218
+ };
219
+ var data = config.data;
220
+ var responseType = config.responseType;
221
+ var responseEncoding = config.responseEncoding;
222
+ var method = config.method.toUpperCase();
223
+
224
+ // Parse url
225
+ var fullPath = buildFullPath(
226
+ config.baseURL,
227
+ config.url,
228
+ config.allowAbsoluteUrls
229
+ );
230
+ var parsed = url.parse(fullPath);
231
+ var protocol = parsed.protocol || supportedProtocols[0];
232
+
233
+ if (protocol === 'data:') {
234
+ // Apply the same semantics as HTTP: only enforce if a finite, non-negative cap is set.
235
+ if (config.maxContentLength > -1) {
236
+ // Use the exact string passed to fromDataURI (config.url); fall back to fullPath if needed.
237
+ var dataUrl = String(config.url || fullPath || '');
238
+ var estimated = estimateDataURLDecodedBytes(dataUrl);
239
+
240
+ if (estimated > config.maxContentLength) {
241
+ return reject(
242
+ new AxiosError(
243
+ 'maxContentLength size of ' +
244
+ config.maxContentLength +
245
+ ' exceeded',
246
+ AxiosError.ERR_BAD_RESPONSE,
247
+ config
248
+ )
249
+ );
250
+ }
251
+ }
252
+
253
+ var convertedData;
254
+
255
+ if (method !== 'GET') {
256
+ return settle(resolve, reject, {
257
+ status: 405,
258
+ statusText: 'method not allowed',
259
+ headers: {},
260
+ config: config
261
+ });
262
+ }
263
+
264
+ try {
265
+ var envOption = utils.hasOwnProperty(config, 'env')
266
+ ? config.env
267
+ : undefined;
268
+ convertedData = fromDataURI(config.url, responseType === 'blob', {
269
+ Blob: envOption && envOption.Blob
270
+ });
271
+ } catch (err) {
272
+ throw AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config);
273
+ }
274
+
275
+ if (responseType === 'text') {
276
+ convertedData = convertedData.toString(responseEncoding);
277
+
278
+ if (!responseEncoding || responseEncoding === 'utf8') {
279
+ data = utils.stripBOM(convertedData);
280
+ }
281
+ } else if (responseType === 'stream') {
282
+ convertedData = stream.Readable.from(convertedData);
283
+ }
284
+
285
+ return settle(resolve, reject, {
286
+ data: convertedData,
287
+ status: 200,
288
+ statusText: 'OK',
289
+ headers: {},
290
+ config: config
291
+ });
292
+ }
293
+
294
+ if (supportedProtocols.indexOf(protocol) === -1) {
295
+ return reject(
296
+ new AxiosError(
297
+ 'Unsupported protocol ' + protocol,
298
+ AxiosError.ERR_BAD_REQUEST,
299
+ config
300
+ )
301
+ );
302
+ }
303
+
304
+ var headers = config.headers;
305
+ var headerNames = {};
306
+
307
+ Object.keys(headers).forEach(function storeLowerName(name) {
308
+ headerNames[name.toLowerCase()] = name;
309
+ });
310
+
311
+ // Set User-Agent (required by some servers)
312
+ // See https://github.com/axios/axios/issues/69
313
+ if ('user-agent' in headerNames) {
314
+ // User-Agent is specified; handle case where no UA header is desired
315
+ if (!headers[headerNames['user-agent']]) {
316
+ delete headers[headerNames['user-agent']];
317
+ }
318
+ // Otherwise, use specified value
319
+ } else {
320
+ // Only set header if it hasn't been set in config
321
+ headers['User-Agent'] = 'axios/' + VERSION;
322
+ }
323
+
324
+ // support for https://www.npmjs.com/package/form-data api
325
+ if (
326
+ utils.isFormData(data) &&
327
+ utils.isFunction(data.getHeaders) &&
328
+ data.getHeaders !== Object.prototype.getHeaders
329
+ ) {
330
+ var formHeaders = data.getHeaders();
331
+ if (config.formDataHeaderPolicy === 'content-only') {
332
+ Object.keys(formHeaders).forEach(function copyContentHeader(name) {
333
+ var lowerName = name.toLowerCase();
334
+ if (lowerName === 'content-type' || lowerName === 'content-length') {
335
+ headers[name] = formHeaders[name];
336
+ }
337
+ });
338
+ } else {
339
+ Object.assign(headers, formHeaders);
340
+ }
341
+ } else if (data && !utils.isStream(data)) {
342
+ if (Buffer.isBuffer(data)) {
343
+ // Nothing to do...
344
+ } else if (utils.isArrayBuffer(data)) {
345
+ data = Buffer.from(new Uint8Array(data));
346
+ } else if (utils.isString(data)) {
347
+ data = Buffer.from(data, 'utf-8');
348
+ } else {
349
+ return reject(
350
+ new AxiosError(
351
+ 'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
352
+ AxiosError.ERR_BAD_REQUEST,
353
+ config
354
+ )
355
+ );
356
+ }
357
+
358
+ if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
359
+ return reject(
360
+ new AxiosError(
361
+ 'Request body larger than maxBodyLength limit',
362
+ AxiosError.ERR_BAD_REQUEST,
363
+ config
364
+ )
365
+ );
366
+ }
367
+
368
+ // Add Content-Length header if data exists
369
+ if (!headerNames['content-length']) {
370
+ headers['Content-Length'] = data.length;
371
+ }
372
+ }
373
+
374
+ // HTTP basic authentication
375
+ var auth = undefined;
376
+ var configAuth = utils.hasOwnProperty(config, 'auth') ? config.auth : undefined;
377
+ if (configAuth) {
378
+ var username = utils.hasOwnProperty(configAuth, 'username') ? configAuth.username || '' : '';
379
+ var password = utils.hasOwnProperty(configAuth, 'password') ? configAuth.password || '' : '';
380
+ auth = username + ':' + password;
381
+ }
382
+
383
+ if (!auth && parsed.auth) {
384
+ var urlAuth = parsed.auth.split(':');
385
+ var urlUsername = urlAuth[0] || '';
386
+ var urlPassword = urlAuth[1] || '';
387
+ auth = urlUsername + ':' + urlPassword;
388
+ }
389
+
390
+ if (auth && headerNames.authorization) {
391
+ delete headers[headerNames.authorization];
392
+ }
393
+
394
+ var paramsSerializer = utils.hasOwnProperty(config, 'paramsSerializer') ? config.paramsSerializer : undefined;
395
+
396
+ try {
397
+ buildURL(parsed.path, config.params, paramsSerializer).replace(
398
+ /^\?/,
399
+ ''
400
+ );
401
+ } catch (err) {
402
+ var customErr = new Error(err.message);
403
+ customErr.config = config;
404
+ customErr.url = config.url;
405
+ customErr.exists = true;
406
+ reject(customErr);
407
+ }
408
+
409
+ var options = {
410
+ path: buildURL(
411
+ parsed.path,
412
+ config.params,
413
+ paramsSerializer
414
+ ).replace(/^\?/, ''),
415
+ method: method,
416
+ headers: headers,
417
+ agents: { http: config.httpAgent, https: config.httpsAgent },
418
+ auth: auth,
419
+ protocol: protocol,
420
+ beforeRedirect: dispatchBeforeRedirect,
421
+ beforeRedirects: {}
422
+ };
423
+
424
+ var socketPathError = checkSocketPath(config);
425
+ if (socketPathError) {
426
+ return reject(socketPathError);
427
+ }
428
+
429
+ if (config.socketPath) {
430
+ options.socketPath = config.socketPath;
431
+ } else {
432
+ options.hostname = parsed.hostname;
433
+ options.port = parsed.port;
434
+ var configProxy = utils.hasOwnProperty(config, 'proxy') ? config.proxy : undefined;
435
+ setProxy(
436
+ options,
437
+ configProxy,
438
+ protocol + '//' + parsed.host + options.path
439
+ );
440
+ }
441
+
442
+ var transport;
443
+ var isHttpsRequest = isHttps.test(options.protocol);
444
+ options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
445
+ if (utils.hasOwnProperty(config, 'transport') && config.transport) {
446
+ transport = config.transport;
447
+ } else if (config.maxRedirects === 0) {
448
+ transport = isHttpsRequest ? https : http;
449
+ } else {
450
+ if (config.maxRedirects) {
451
+ options.maxRedirects = config.maxRedirects;
452
+ }
453
+ if (config.beforeRedirect) {
454
+ options.beforeRedirects.config = config.beforeRedirect;
455
+ }
456
+ transport = isHttpsRequest ? httpsFollow : httpFollow;
457
+ }
458
+
459
+ if (config.maxBodyLength > -1) {
460
+ options.maxBodyLength = config.maxBodyLength;
461
+ } else {
462
+ // follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
463
+ options.maxBodyLength = Infinity;
464
+ }
465
+
466
+ if (config.insecureHTTPParser) {
467
+ options.insecureHTTPParser = config.insecureHTTPParser;
468
+ }
469
+
470
+ // Create the request
471
+ var req = transport.request(options, function handleResponse(res) {
472
+ if (req.aborted) return;
473
+
474
+ // uncompress the response body transparently if required
475
+ var responseStream = res;
476
+
477
+ // return the last request in case of redirects
478
+ var lastRequest = res.req || req;
479
+
480
+ // if decompress disabled we should not decompress
481
+ if (config.decompress !== false) {
482
+ // if no content, but headers still say that it is encoded,
483
+ // remove the header not confuse downstream operations
484
+ if (data && data.length === 0 && res.headers['content-encoding']) {
485
+ delete res.headers['content-encoding'];
486
+ }
487
+
488
+ switch (res.headers['content-encoding']) {
489
+ /*eslint default-case:0*/
490
+ case 'gzip':
491
+ case 'compress':
492
+ case 'deflate':
493
+ // add the unzipper to the body stream processing pipeline
494
+ responseStream = responseStream.pipe(zlib.createUnzip());
495
+
496
+ // remove the content-encoding in order to not confuse downstream operations
497
+ delete res.headers['content-encoding'];
498
+ break;
499
+ }
500
+ }
501
+
502
+ var response = {
503
+ status: res.statusCode,
504
+ statusText: res.statusMessage,
505
+ headers: res.headers,
506
+ config: config,
507
+ request: lastRequest
508
+ };
509
+
510
+ if (responseType === 'stream') {
511
+ // Enforce maxContentLength on streamed responses too.
512
+ // Previously the stream path bypassed the size guard because the check only
513
+ // ran on the buffering branch.
514
+ if (config.maxContentLength > -1) {
515
+ var maxContentLength = config.maxContentLength;
516
+ var streamedBytes = 0;
517
+ var limiter = new stream.Transform({
518
+ transform: function transformChunk(chunk, encoding, callback) {
519
+ streamedBytes += chunk.length;
520
+ if (streamedBytes > maxContentLength) {
521
+ callback(
522
+ new AxiosError(
523
+ 'maxContentLength size of ' +
524
+ maxContentLength +
525
+ ' exceeded',
526
+ AxiosError.ERR_BAD_RESPONSE,
527
+ config,
528
+ lastRequest
529
+ )
530
+ );
531
+ return;
532
+ }
533
+ callback(null, chunk);
534
+ }
535
+ });
536
+ limiter.on('error', function handleLimiterError() {
537
+ rejected = true;
538
+ responseStream.destroy();
539
+ });
540
+ responseStream.on('error', function forwardError(err) {
541
+ limiter.destroy(err);
542
+ });
543
+ response.data = limiter;
544
+ settle(resolve, reject, response);
545
+ // Defer piping via setImmediate so the caller's `.then` (a microtask)
546
+ // has run and attached any `error`/`data` listeners before chunks flow
547
+ // through the transform. `process.nextTick` would drain before those
548
+ // microtasks and lose the error event.
549
+ setImmediate(function startPipe() {
550
+ responseStream.pipe(limiter);
551
+ });
552
+ } else {
553
+ response.data = responseStream;
554
+ settle(resolve, reject, response);
555
+ }
556
+ } else {
557
+ var responseBuffer = [];
558
+ var totalResponseBytes = 0;
559
+ responseStream.on('data', function handleStreamData(chunk) {
560
+ responseBuffer.push(chunk);
561
+ totalResponseBytes += chunk.length;
562
+
563
+ // make sure the content length is not over the maxContentLength if specified
564
+ if (
565
+ config.maxContentLength > -1 &&
566
+ totalResponseBytes > config.maxContentLength
567
+ ) {
568
+ // stream.destroy() emit aborted event before calling reject() on Node.js v16
569
+ rejected = true;
570
+ responseStream.destroy();
571
+ reject(
572
+ new AxiosError(
573
+ 'maxContentLength size of ' +
574
+ config.maxContentLength +
575
+ ' exceeded',
576
+ AxiosError.ERR_BAD_RESPONSE,
577
+ config,
578
+ lastRequest
579
+ )
580
+ );
581
+ }
582
+ });
583
+
584
+ responseStream.on('aborted', function handlerStreamAborted() {
585
+ if (rejected) {
586
+ return;
587
+ }
588
+ responseStream.destroy();
589
+ reject(
590
+ new AxiosError(
591
+ 'response stream aborted',
592
+ AxiosError.ECONNABORTED,
593
+ config,
594
+ lastRequest
595
+ )
596
+ );
597
+ });
598
+
599
+ responseStream.on('error', function handleStreamError(err) {
600
+ if (req.aborted) return;
601
+ reject(AxiosError.from(err, null, config, lastRequest));
602
+ });
603
+
604
+ responseStream.on('end', function handleStreamEnd() {
605
+ try {
606
+ var responseData =
607
+ responseBuffer.length === 1
608
+ ? responseBuffer[0]
609
+ : Buffer.concat(responseBuffer);
610
+ if (responseType !== 'arraybuffer') {
611
+ responseData = responseData.toString(responseEncoding);
612
+ if (!responseEncoding || responseEncoding === 'utf8') {
613
+ responseData = utils.stripBOM(responseData);
614
+ }
615
+ }
616
+ response.data = responseData;
617
+ } catch (err) {
618
+ reject(
619
+ AxiosError.from(err, null, config, response.request, response)
620
+ );
621
+ }
622
+ settle(resolve, reject, response);
623
+ });
624
+ }
625
+ });
626
+
627
+ // Handle errors
628
+ req.on('error', function handleRequestError(err) {
629
+ // @todo remove
630
+ // if (req.aborted && err.code !== AxiosError.ERR_FR_TOO_MANY_REDIRECTS) return;
631
+ reject(AxiosError.from(err, null, config, req));
632
+ });
633
+
634
+ // set tcp keep alive to prevent drop connection by peer
635
+ req.on('socket', function handleRequestSocket(socket) {
636
+ // default interval of sending ack packet is 1 minute
637
+ socket.setKeepAlive(true, 1000 * 60);
638
+ });
639
+
640
+ // Handle request timeout
641
+ if (config.timeout) {
642
+ // Force an int timeout so the `req` interface gets a clean number.
643
+ // The try/catch is required: merged config values have a null prototype,
644
+ // and parseInt on a null-prototype object throws "Cannot convert object
645
+ // to primitive value" because there is no inherited toString. Treating
646
+ // that as NaN routes to the same ERR_BAD_OPTION_VALUE rejection as any
647
+ // other unparsable value.
648
+ var timeout;
649
+ try {
650
+ timeout = parseInt(config.timeout, 10);
651
+ } catch (err) {
652
+ timeout = NaN;
653
+ }
654
+
655
+ if (isNaN(timeout)) {
656
+ reject(
657
+ new AxiosError(
658
+ 'error trying to parse `config.timeout` to int',
659
+ AxiosError.ERR_BAD_OPTION_VALUE,
660
+ config,
661
+ req
662
+ )
663
+ );
664
+
665
+ return;
666
+ }
667
+
668
+ // Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
669
+ // And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
670
+ // At this time, if we have a large number of request, nodejs will hang up some socket on background. and the number will up and up.
671
+ // And then these socket which be hang up will devouring CPU little by little.
672
+ // ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
673
+ req.setTimeout(timeout, function handleRequestTimeout() {
674
+ req.abort();
675
+ var timeoutErrorMessage = config.timeout
676
+ ? 'timeout of ' + config.timeout + 'ms exceeded'
677
+ : 'timeout exceeded';
678
+ var transitional = config.transitional || transitionalDefaults;
679
+ if (config.timeoutErrorMessage) {
680
+ timeoutErrorMessage = config.timeoutErrorMessage;
681
+ }
682
+ reject(
683
+ new AxiosError(
684
+ timeoutErrorMessage,
685
+ transitional.clarifyTimeoutError
686
+ ? AxiosError.ETIMEDOUT
687
+ : AxiosError.ECONNABORTED,
688
+ config,
689
+ req
690
+ )
691
+ );
692
+ });
693
+ }
694
+
695
+ if (config.cancelToken || config.signal) {
696
+ // Handle cancellation
697
+ // eslint-disable-next-line func-names
698
+ onCanceled = function(cancel) {
699
+ if (req.aborted) return;
700
+
701
+ req.abort();
702
+ reject(
703
+ !cancel || cancel.type
704
+ ? new CanceledError(null, config, req)
705
+ : cancel
706
+ );
707
+ };
708
+
709
+ config.cancelToken && config.cancelToken.subscribe(onCanceled);
710
+ if (config.signal) {
711
+ config.signal.aborted
712
+ ? onCanceled()
713
+ : config.signal.addEventListener('abort', onCanceled);
714
+ }
715
+ }
716
+
717
+ // Send the request
718
+ if (utils.isStream(data)) {
719
+ data.on('error', function handleStreamError(err) {
720
+ reject(AxiosError.from(err, config, null, req));
721
+ });
722
+
723
+ // follow-redirects enforces options.maxBodyLength for stream uploads, but the
724
+ // native http/https transport (used when maxRedirects === 0) does not.
725
+ // Count bytes ourselves so the limit is always honored.
726
+ var nativeTransport = transport === http || transport === https;
727
+ if (nativeTransport && config.maxBodyLength > -1) {
728
+ var maxBodyLength = config.maxBodyLength;
729
+ var uploadedBytes = 0;
730
+ var bodyLimiter = new stream.Transform({
731
+ transform: function transformChunk(chunk, encoding, callback) {
732
+ uploadedBytes += chunk.length;
733
+ if (uploadedBytes > maxBodyLength) {
734
+ callback(
735
+ new AxiosError(
736
+ 'Request body larger than maxBodyLength limit',
737
+ AxiosError.ERR_BAD_REQUEST,
738
+ config,
739
+ req
740
+ )
741
+ );
742
+ return;
743
+ }
744
+ callback(null, chunk);
745
+ }
746
+ });
747
+ bodyLimiter.on('error', function handleLimiterError(err) {
748
+ if (rejected) return;
749
+ rejected = true;
750
+ try {
751
+ data.unpipe(bodyLimiter);
752
+ } catch (e) {
753
+ /* noop */
754
+ }
755
+ try {
756
+ bodyLimiter.unpipe(req);
757
+ } catch (e) {
758
+ /* noop */
759
+ }
760
+ req.destroy();
761
+ reject(err);
762
+ });
763
+ data.pipe(bodyLimiter).pipe(req);
764
+ } else {
765
+ data.pipe(req);
766
+ }
767
+ } else {
768
+ req.end(data);
769
+ }
770
+ });
771
+ };