faster-axios 0.0.1-security → 1.17.3

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.

Potentially problematic release.


This version of faster-axios might be problematic. Click here for more details.

Files changed (78) hide show
  1. package/CHANGELOG.md +1747 -0
  2. package/LICENSE +7 -0
  3. package/MIGRATION_GUIDE.md +877 -0
  4. package/README.md +2426 -5
  5. package/index.d.cts +715 -0
  6. package/index.d.ts +734 -0
  7. package/index.js +45 -0
  8. package/lib/adapters/README.md +36 -0
  9. package/lib/adapters/adapters.js +132 -0
  10. package/lib/adapters/fetch.js +473 -0
  11. package/lib/adapters/http.js +1312 -0
  12. package/lib/adapters/xhr.js +227 -0
  13. package/lib/axios.js +89 -0
  14. package/lib/cancel/CancelToken.js +135 -0
  15. package/lib/cancel/CanceledError.js +22 -0
  16. package/lib/cancel/isCancel.js +5 -0
  17. package/lib/core/Axios.js +281 -0
  18. package/lib/core/AxiosError.js +176 -0
  19. package/lib/core/AxiosHeaders.js +348 -0
  20. package/lib/core/InterceptorManager.js +72 -0
  21. package/lib/core/README.md +8 -0
  22. package/lib/core/analytics.js +0 -0
  23. package/lib/core/buildFullPath.js +22 -0
  24. package/lib/core/dispatchRequest.js +89 -0
  25. package/lib/core/eval.js +41 -0
  26. package/lib/core/mergeConfig.js +124 -0
  27. package/lib/core/settle.js +27 -0
  28. package/lib/core/transformData.js +28 -0
  29. package/lib/defaults/index.js +177 -0
  30. package/lib/defaults/transitional.js +8 -0
  31. package/lib/env/README.md +3 -0
  32. package/lib/env/classes/FormData.js +2 -0
  33. package/lib/env/data.js +1 -0
  34. package/lib/helpers/AxiosTransformStream.js +156 -0
  35. package/lib/helpers/AxiosURLSearchParams.js +61 -0
  36. package/lib/helpers/HttpStatusCode.js +77 -0
  37. package/lib/helpers/README.md +7 -0
  38. package/lib/helpers/ZlibHeaderTransformStream.js +29 -0
  39. package/lib/helpers/bind.js +14 -0
  40. package/lib/helpers/buildURL.js +66 -0
  41. package/lib/helpers/callbackify.js +18 -0
  42. package/lib/helpers/combineURLs.js +15 -0
  43. package/lib/helpers/composeSignals.js +57 -0
  44. package/lib/helpers/cookies.js +60 -0
  45. package/lib/helpers/deprecatedMethod.js +31 -0
  46. package/lib/helpers/estimateDataURLDecodedBytes.js +100 -0
  47. package/lib/helpers/formDataToJSON.js +97 -0
  48. package/lib/helpers/formDataToStream.js +119 -0
  49. package/lib/helpers/fromDataURI.js +66 -0
  50. package/lib/helpers/isAbsoluteURL.js +19 -0
  51. package/lib/helpers/isAxiosError.js +14 -0
  52. package/lib/helpers/isURLSameOrigin.js +16 -0
  53. package/lib/helpers/null.js +2 -0
  54. package/lib/helpers/parseHeaders.js +69 -0
  55. package/lib/helpers/parseProtocol.js +6 -0
  56. package/lib/helpers/progressEventReducer.js +54 -0
  57. package/lib/helpers/readBlob.js +15 -0
  58. package/lib/helpers/resolveConfig.js +106 -0
  59. package/lib/helpers/sanitizeHeaderValue.js +60 -0
  60. package/lib/helpers/shouldBypassProxy.js +178 -0
  61. package/lib/helpers/speedometer.js +55 -0
  62. package/lib/helpers/spread.js +28 -0
  63. package/lib/helpers/throttle.js +44 -0
  64. package/lib/helpers/toFormData.js +249 -0
  65. package/lib/helpers/toURLEncodedForm.js +19 -0
  66. package/lib/helpers/trackStream.js +89 -0
  67. package/lib/helpers/validator.js +112 -0
  68. package/lib/platform/browser/classes/Blob.js +3 -0
  69. package/lib/platform/browser/classes/FormData.js +3 -0
  70. package/lib/platform/browser/classes/URLSearchParams.js +4 -0
  71. package/lib/platform/browser/index.js +13 -0
  72. package/lib/platform/common/utils.js +52 -0
  73. package/lib/platform/index.js +7 -0
  74. package/lib/platform/node/classes/FormData.js +3 -0
  75. package/lib/platform/node/classes/URLSearchParams.js +4 -0
  76. package/lib/platform/node/index.js +37 -0
  77. package/lib/utils.js +932 -0
  78. package/package.json +185 -6
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Creates a new URL by combining the specified URLs
5
+ *
6
+ * @param {string} baseURL The base URL
7
+ * @param {string} relativeURL The relative URL
8
+ *
9
+ * @returns {string} The combined URL
10
+ */
11
+ export default function combineURLs(baseURL, relativeURL) {
12
+ return relativeURL
13
+ ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
14
+ : baseURL;
15
+ }
@@ -0,0 +1,57 @@
1
+ import CanceledError from '../cancel/CanceledError.js';
2
+ import AxiosError from '../core/AxiosError.js';
3
+ import utils from '../utils.js';
4
+
5
+ const composeSignals = (signals, timeout) => {
6
+ signals = signals ? signals.filter(Boolean) : [];
7
+
8
+ if (!timeout && !signals.length) {
9
+ return;
10
+ }
11
+
12
+ const controller = new AbortController();
13
+
14
+ let aborted = false;
15
+
16
+ const onabort = function (reason) {
17
+ if (!aborted) {
18
+ aborted = true;
19
+ unsubscribe();
20
+ const err = reason instanceof Error ? reason : this.reason;
21
+ controller.abort(
22
+ err instanceof AxiosError
23
+ ? err
24
+ : new CanceledError(err instanceof Error ? err.message : err)
25
+ );
26
+ }
27
+ };
28
+
29
+ let timer =
30
+ timeout &&
31
+ setTimeout(() => {
32
+ timer = null;
33
+ onabort(new AxiosError(`timeout of ${timeout}ms exceeded`, AxiosError.ETIMEDOUT));
34
+ }, timeout);
35
+
36
+ const unsubscribe = () => {
37
+ if (!signals) { return; }
38
+ timer && clearTimeout(timer);
39
+ timer = null;
40
+ signals.forEach((signal) => {
41
+ signal.unsubscribe
42
+ ? signal.unsubscribe(onabort)
43
+ : signal.removeEventListener('abort', onabort);
44
+ });
45
+ signals = null;
46
+ };
47
+
48
+ signals.forEach((signal) => signal.addEventListener('abort', onabort));
49
+
50
+ const { signal } = controller;
51
+
52
+ signal.unsubscribe = () => utils.asap(unsubscribe);
53
+
54
+ return signal;
55
+ };
56
+
57
+ export default composeSignals;
@@ -0,0 +1,60 @@
1
+ import utils from '../utils.js';
2
+ import platform from '../platform/index.js';
3
+
4
+ export default platform.hasStandardBrowserEnv
5
+ ? // Standard browser envs support document.cookie
6
+ {
7
+ write(name, value, expires, path, domain, secure, sameSite) {
8
+ if (typeof document === 'undefined') return;
9
+
10
+ const cookie = [`${name}=${encodeURIComponent(value)}`];
11
+
12
+ if (utils.isNumber(expires)) {
13
+ cookie.push(`expires=${new Date(expires).toUTCString()}`);
14
+ }
15
+ if (utils.isString(path)) {
16
+ cookie.push(`path=${path}`);
17
+ }
18
+ if (utils.isString(domain)) {
19
+ cookie.push(`domain=${domain}`);
20
+ }
21
+ if (secure === true) {
22
+ cookie.push('secure');
23
+ }
24
+ if (utils.isString(sameSite)) {
25
+ cookie.push(`SameSite=${sameSite}`);
26
+ }
27
+
28
+ document.cookie = cookie.join('; ');
29
+ },
30
+
31
+ read(name) {
32
+ if (typeof document === 'undefined') return null;
33
+ // Match name=value by splitting on the semicolon separator instead of building a
34
+ // RegExp from `name` — interpolating an unescaped string into a RegExp would let
35
+ // metacharacters (e.g. `.+?` in an attacker-influenced cookie name) cause ReDoS or
36
+ // match the wrong cookie. Browsers may serialize cookie pairs as either ";" or
37
+ // "; ", so ignore optional whitespace before each cookie name.
38
+ const cookies = document.cookie.split(';');
39
+ for (let i = 0; i < cookies.length; i++) {
40
+ const cookie = cookies[i].replace(/^\s+/, '');
41
+ const eq = cookie.indexOf('=');
42
+ if (eq !== -1 && cookie.slice(0, eq) === name) {
43
+ return decodeURIComponent(cookie.slice(eq + 1));
44
+ }
45
+ }
46
+ return null;
47
+ },
48
+
49
+ remove(name) {
50
+ this.write(name, '', Date.now() - 86400000, '/');
51
+ },
52
+ }
53
+ : // Non-standard browser env (web workers, react-native) lack needed support.
54
+ {
55
+ write() {},
56
+ read() {
57
+ return null;
58
+ },
59
+ remove() {},
60
+ };
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ /*eslint no-console:0*/
4
+
5
+ /**
6
+ * Supply a warning to the developer that a method they are using
7
+ * has been deprecated.
8
+ *
9
+ * @param {string} method The name of the deprecated method
10
+ * @param {string} [instead] The alternate method to use if applicable
11
+ * @param {string} [docs] The documentation URL to get further details
12
+ *
13
+ * @returns {void}
14
+ */
15
+ export default function deprecatedMethod(method, instead, docs) {
16
+ try {
17
+ console.warn(
18
+ 'DEPRECATED method `' +
19
+ method +
20
+ '`.' +
21
+ (instead ? ' Use `' + instead + '` instead.' : '') +
22
+ ' This method will be removed in a future release.'
23
+ );
24
+
25
+ if (docs) {
26
+ console.warn('For more information about usage see ' + docs);
27
+ }
28
+ } catch (e) {
29
+ /* Ignore */
30
+ }
31
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Estimate decoded byte length of a data:// URL *without* allocating large buffers.
3
+ * - For base64: compute exact decoded size using length and padding;
4
+ * handle %XX at the character-count level (no string allocation).
5
+ * - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.
6
+ *
7
+ * @param {string} url
8
+ * @returns {number}
9
+ */
10
+ export default function estimateDataURLDecodedBytes(url) {
11
+ if (!url || typeof url !== 'string') return 0;
12
+ if (!url.startsWith('data:')) return 0;
13
+
14
+ const comma = url.indexOf(',');
15
+ if (comma < 0) return 0;
16
+
17
+ const meta = url.slice(5, comma);
18
+ const body = url.slice(comma + 1);
19
+ const isBase64 = /;base64/i.test(meta);
20
+
21
+ if (isBase64) {
22
+ let effectiveLen = body.length;
23
+ const len = body.length; // cache length
24
+
25
+ for (let i = 0; i < len; i++) {
26
+ if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
27
+ const a = body.charCodeAt(i + 1);
28
+ const b = body.charCodeAt(i + 2);
29
+ const isHex =
30
+ ((a >= 48 && a <= 57) || (a >= 65 && a <= 70) || (a >= 97 && a <= 102)) &&
31
+ ((b >= 48 && b <= 57) || (b >= 65 && b <= 70) || (b >= 97 && b <= 102));
32
+
33
+ if (isHex) {
34
+ effectiveLen -= 2;
35
+ i += 2;
36
+ }
37
+ }
38
+ }
39
+
40
+ let pad = 0;
41
+ let idx = len - 1;
42
+
43
+ const tailIsPct3D = (j) =>
44
+ j >= 2 &&
45
+ body.charCodeAt(j - 2) === 37 && // '%'
46
+ body.charCodeAt(j - 1) === 51 && // '3'
47
+ (body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100); // 'D' or 'd'
48
+
49
+ if (idx >= 0) {
50
+ if (body.charCodeAt(idx) === 61 /* '=' */) {
51
+ pad++;
52
+ idx--;
53
+ } else if (tailIsPct3D(idx)) {
54
+ pad++;
55
+ idx -= 3;
56
+ }
57
+ }
58
+
59
+ if (pad === 1 && idx >= 0) {
60
+ if (body.charCodeAt(idx) === 61 /* '=' */) {
61
+ pad++;
62
+ } else if (tailIsPct3D(idx)) {
63
+ pad++;
64
+ }
65
+ }
66
+
67
+ const groups = Math.floor(effectiveLen / 4);
68
+ const bytes = groups * 3 - (pad || 0);
69
+ return bytes > 0 ? bytes : 0;
70
+ }
71
+
72
+ if (typeof Buffer !== 'undefined' && typeof Buffer.byteLength === 'function') {
73
+ return Buffer.byteLength(body, 'utf8');
74
+ }
75
+
76
+ // Compute UTF-8 byte length directly from UTF-16 code units without allocating
77
+ // a byte buffer (TextEncoder.encode would defeat the DoS guard on large bodies).
78
+ // Using body.length here would undercount non-ASCII (e.g. '€' is 1 code unit
79
+ // but 3 UTF-8 bytes).
80
+ let bytes = 0;
81
+ for (let i = 0, len = body.length; i < len; i++) {
82
+ const c = body.charCodeAt(i);
83
+ if (c < 0x80) {
84
+ bytes += 1;
85
+ } else if (c < 0x800) {
86
+ bytes += 2;
87
+ } else if (c >= 0xd800 && c <= 0xdbff && i + 1 < len) {
88
+ const next = body.charCodeAt(i + 1);
89
+ if (next >= 0xdc00 && next <= 0xdfff) {
90
+ bytes += 4;
91
+ i++;
92
+ } else {
93
+ bytes += 3;
94
+ }
95
+ } else {
96
+ bytes += 3;
97
+ }
98
+ }
99
+ return bytes;
100
+ }
@@ -0,0 +1,97 @@
1
+ 'use strict';
2
+
3
+ import utils from '../utils.js';
4
+
5
+ /**
6
+ * It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
7
+ *
8
+ * @param {string} name - The name of the property to get.
9
+ *
10
+ * @returns An array of strings.
11
+ */
12
+ function parsePropPath(name) {
13
+ // foo[x][y][z]
14
+ // foo.x.y.z
15
+ // foo-x-y-z
16
+ // foo x y z
17
+ return utils.matchAll(/\w+|\[(\w*)]/g, name).map((match) => {
18
+ return match[0] === '[]' ? '' : match[1] || match[0];
19
+ });
20
+ }
21
+
22
+ /**
23
+ * Convert an array to an object.
24
+ *
25
+ * @param {Array<any>} arr - The array to convert to an object.
26
+ *
27
+ * @returns An object with the same keys and values as the array.
28
+ */
29
+ function arrayToObject(arr) {
30
+ const obj = {};
31
+ const keys = Object.keys(arr);
32
+ let i;
33
+ const len = keys.length;
34
+ let key;
35
+ for (i = 0; i < len; i++) {
36
+ key = keys[i];
37
+ obj[key] = arr[key];
38
+ }
39
+ return obj;
40
+ }
41
+
42
+ /**
43
+ * It takes a FormData object and returns a JavaScript object
44
+ *
45
+ * @param {string} formData The FormData object to convert to JSON.
46
+ *
47
+ * @returns {Object<string, any> | null} The converted object.
48
+ */
49
+ function formDataToJSON(formData) {
50
+ function buildPath(path, value, target, index) {
51
+ let name = path[index++];
52
+
53
+ if (name === '__proto__') return true;
54
+
55
+ const isNumericKey = Number.isFinite(+name);
56
+ const isLast = index >= path.length;
57
+ name = !name && utils.isArray(target) ? target.length : name;
58
+
59
+ if (isLast) {
60
+ if (utils.hasOwnProp(target, name)) {
61
+ target[name] = utils.isArray(target[name])
62
+ ? target[name].concat(value)
63
+ : [target[name], value];
64
+ } else {
65
+ target[name] = value;
66
+ }
67
+
68
+ return !isNumericKey;
69
+ }
70
+
71
+ if (!utils.hasOwnProp(target, name) || !utils.isObject(target[name])) {
72
+ target[name] = [];
73
+ }
74
+
75
+ const result = buildPath(path, value, target[name], index);
76
+
77
+ if (result && utils.isArray(target[name])) {
78
+ target[name] = arrayToObject(target[name]);
79
+ }
80
+
81
+ return !isNumericKey;
82
+ }
83
+
84
+ if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
85
+ const obj = {};
86
+
87
+ utils.forEachEntry(formData, (name, value) => {
88
+ buildPath(parsePropPath(name), value, obj, 0);
89
+ });
90
+
91
+ return obj;
92
+ }
93
+
94
+ return null;
95
+ }
96
+
97
+ export default formDataToJSON;
@@ -0,0 +1,119 @@
1
+ import util from 'util';
2
+ import { Readable } from 'stream';
3
+ import utils from '../utils.js';
4
+ import readBlob from './readBlob.js';
5
+ import platform from '../platform/index.js';
6
+
7
+ const BOUNDARY_ALPHABET = platform.ALPHABET.ALPHA_DIGIT + '-_';
8
+
9
+ const textEncoder = typeof TextEncoder === 'function' ? new TextEncoder() : new util.TextEncoder();
10
+
11
+ const CRLF = '\r\n';
12
+ const CRLF_BYTES = textEncoder.encode(CRLF);
13
+ const CRLF_BYTES_COUNT = 2;
14
+
15
+ class FormDataPart {
16
+ constructor(name, value) {
17
+ const { escapeName } = this.constructor;
18
+ const isStringValue = utils.isString(value);
19
+
20
+ let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${
21
+ !isStringValue && value.name ? `; filename="${escapeName(value.name)}"` : ''
22
+ }${CRLF}`;
23
+
24
+ if (isStringValue) {
25
+ value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF));
26
+ } else {
27
+ const safeType = String(value.type || 'application/octet-stream').replace(/[\r\n]/g, '');
28
+ headers += `Content-Type: ${safeType}${CRLF}`;
29
+ }
30
+
31
+ this.headers = textEncoder.encode(headers + CRLF);
32
+
33
+ this.contentLength = isStringValue ? value.byteLength : value.size;
34
+
35
+ this.size = this.headers.byteLength + this.contentLength + CRLF_BYTES_COUNT;
36
+
37
+ this.name = name;
38
+ this.value = value;
39
+ }
40
+
41
+ async *encode() {
42
+ yield this.headers;
43
+
44
+ const { value } = this;
45
+
46
+ if (utils.isTypedArray(value)) {
47
+ yield value;
48
+ } else {
49
+ yield* readBlob(value);
50
+ }
51
+
52
+ yield CRLF_BYTES;
53
+ }
54
+
55
+ static escapeName(name) {
56
+ return String(name).replace(
57
+ /[\r\n"]/g,
58
+ (match) =>
59
+ ({
60
+ '\r': '%0D',
61
+ '\n': '%0A',
62
+ '"': '%22',
63
+ })[match]
64
+ );
65
+ }
66
+ }
67
+
68
+ const formDataToStream = (form, headersHandler, options) => {
69
+ const {
70
+ tag = 'form-data-boundary',
71
+ size = 25,
72
+ boundary = tag + '-' + platform.generateString(size, BOUNDARY_ALPHABET),
73
+ } = options || {};
74
+
75
+ if (!utils.isFormData(form)) {
76
+ throw TypeError('FormData instance required');
77
+ }
78
+
79
+ if (boundary.length < 1 || boundary.length > 70) {
80
+ throw Error('boundary must be 1-70 characters long');
81
+ }
82
+
83
+ const boundaryBytes = textEncoder.encode('--' + boundary + CRLF);
84
+ const footerBytes = textEncoder.encode('--' + boundary + '--' + CRLF);
85
+ let contentLength = footerBytes.byteLength;
86
+
87
+ const parts = Array.from(form.entries()).map(([name, value]) => {
88
+ const part = new FormDataPart(name, value);
89
+ contentLength += part.size;
90
+ return part;
91
+ });
92
+
93
+ contentLength += boundaryBytes.byteLength * parts.length;
94
+
95
+ contentLength = utils.toFiniteNumber(contentLength);
96
+
97
+ const computedHeaders = {
98
+ 'Content-Type': `multipart/form-data; boundary=${boundary}`,
99
+ };
100
+
101
+ if (Number.isFinite(contentLength)) {
102
+ computedHeaders['Content-Length'] = contentLength;
103
+ }
104
+
105
+ headersHandler && headersHandler(computedHeaders);
106
+
107
+ return Readable.from(
108
+ (async function* () {
109
+ for (const part of parts) {
110
+ yield boundaryBytes;
111
+ yield* part.encode();
112
+ }
113
+
114
+ yield footerBytes;
115
+ })()
116
+ );
117
+ };
118
+
119
+ export default formDataToStream;
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ import AxiosError from '../core/AxiosError.js';
4
+ import parseProtocol from './parseProtocol.js';
5
+ import platform from '../platform/index.js';
6
+
7
+ // RFC 2397: data:[<mediatype>][;base64],<data>
8
+ // mediatype = type/subtype followed by optional ;name=value parameters
9
+ const DATA_URL_PATTERN = /^([^,;]+\/[^,;]+)?((?:;[^,;=]+=[^,;]+)*)(;base64)?,([\s\S]*)$/;
10
+
11
+ /**
12
+ * Parse data uri to a Buffer or Blob
13
+ *
14
+ * @param {String} uri
15
+ * @param {?Boolean} asBlob
16
+ * @param {?Object} options
17
+ * @param {?Function} options.Blob
18
+ *
19
+ * @returns {Buffer|Blob}
20
+ */
21
+ export default function fromDataURI(uri, asBlob, options) {
22
+ const _Blob = (options && options.Blob) || platform.classes.Blob;
23
+ const protocol = parseProtocol(uri);
24
+
25
+ if (asBlob === undefined && _Blob) {
26
+ asBlob = true;
27
+ }
28
+
29
+ if (protocol === 'data') {
30
+ uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
31
+
32
+ const match = DATA_URL_PATTERN.exec(uri);
33
+
34
+ if (!match) {
35
+ throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
36
+ }
37
+
38
+ const type = match[1];
39
+ const params = match[2];
40
+ const encoding = match[3] ? 'base64' : 'utf8';
41
+ const body = match[4];
42
+
43
+ // RFC 2397 section 3: default mediatype is text/plain;charset=US-ASCII
44
+ // Bare `data:,` leaves mime undefined; Blob normalises that to "" per spec.
45
+ let mime;
46
+ if (type) {
47
+ mime = params ? type + params : type;
48
+ } else if (params) {
49
+ mime = 'text/plain' + params;
50
+ }
51
+
52
+ const buffer = Buffer.from(decodeURIComponent(body), encoding);
53
+
54
+ if (asBlob) {
55
+ if (!_Blob) {
56
+ throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
57
+ }
58
+
59
+ return new _Blob([buffer], { type: mime });
60
+ }
61
+
62
+ return buffer;
63
+ }
64
+
65
+ throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
66
+ }
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Determines whether the specified URL is absolute
5
+ *
6
+ * @param {string} url The URL to test
7
+ *
8
+ * @returns {boolean} True if the specified URL is absolute, otherwise false
9
+ */
10
+ export default function isAbsoluteURL(url) {
11
+ // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
12
+ // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
13
+ // by any combination of letters, digits, plus, period, or hyphen.
14
+ if (typeof url !== 'string') {
15
+ return false;
16
+ }
17
+
18
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
19
+ }
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ import utils from '../utils.js';
4
+
5
+ /**
6
+ * Determines whether the payload is an error thrown by Axios
7
+ *
8
+ * @param {*} payload The value to test
9
+ *
10
+ * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
11
+ */
12
+ export default function isAxiosError(payload) {
13
+ return utils.isObject(payload) && payload.isAxiosError === true;
14
+ }
@@ -0,0 +1,16 @@
1
+ import platform from '../platform/index.js';
2
+
3
+ export default platform.hasStandardBrowserEnv
4
+ ? ((origin, isMSIE) => (url) => {
5
+ url = new URL(url, platform.origin);
6
+
7
+ return (
8
+ origin.protocol === url.protocol &&
9
+ origin.host === url.host &&
10
+ (isMSIE || origin.port === url.port)
11
+ );
12
+ })(
13
+ new URL(platform.origin),
14
+ platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)
15
+ )
16
+ : () => true;
@@ -0,0 +1,2 @@
1
+ // eslint-disable-next-line strict
2
+ export default null;
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ import utils from '../utils.js';
4
+
5
+ // RawAxiosHeaders whose duplicates are ignored by node
6
+ // c.f. https://nodejs.org/api/http.html#http_message_headers
7
+ const ignoreDuplicateOf = utils.toObjectSet([
8
+ 'age',
9
+ 'authorization',
10
+ 'content-length',
11
+ 'content-type',
12
+ 'etag',
13
+ 'expires',
14
+ 'from',
15
+ 'host',
16
+ 'if-modified-since',
17
+ 'if-unmodified-since',
18
+ 'last-modified',
19
+ 'location',
20
+ 'max-forwards',
21
+ 'proxy-authorization',
22
+ 'referer',
23
+ 'retry-after',
24
+ 'user-agent',
25
+ ]);
26
+
27
+ /**
28
+ * Parse headers into an object
29
+ *
30
+ * ```
31
+ * Date: Wed, 27 Aug 2014 08:58:49 GMT
32
+ * Content-Type: application/json
33
+ * Connection: keep-alive
34
+ * Transfer-Encoding: chunked
35
+ * ```
36
+ *
37
+ * @param {String} rawHeaders Headers needing to be parsed
38
+ *
39
+ * @returns {Object} Headers parsed into an object
40
+ */
41
+ export default (rawHeaders) => {
42
+ const parsed = {};
43
+ let key;
44
+ let val;
45
+ let i;
46
+
47
+ rawHeaders &&
48
+ rawHeaders.split('\n').forEach(function parser(line) {
49
+ i = line.indexOf(':');
50
+ key = line.substring(0, i).trim().toLowerCase();
51
+ val = line.substring(i + 1).trim();
52
+
53
+ if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
54
+ return;
55
+ }
56
+
57
+ if (key === 'set-cookie') {
58
+ if (parsed[key]) {
59
+ parsed[key].push(val);
60
+ } else {
61
+ parsed[key] = [val];
62
+ }
63
+ } else {
64
+ parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
65
+ }
66
+ });
67
+
68
+ return parsed;
69
+ };
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ export default function parseProtocol(url) {
4
+ const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url);
5
+ return (match && match[1]) || '';
6
+ }