@lcap/axios-fixed 1.13.2

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 (87) hide show
  1. package/.husky/commit-msg +4 -0
  2. package/CHANGELOG.md +1359 -0
  3. package/LICENSE +7 -0
  4. package/MIGRATION_GUIDE.md +3 -0
  5. package/README.md +1784 -0
  6. package/dist/axios.js +4471 -0
  7. package/dist/axios.js.map +1 -0
  8. package/dist/axios.min.js +3 -0
  9. package/dist/axios.min.js.map +1 -0
  10. package/dist/browser/axios.cjs +3909 -0
  11. package/dist/browser/axios.cjs.map +1 -0
  12. package/dist/esm/axios.js +3932 -0
  13. package/dist/esm/axios.js.map +1 -0
  14. package/dist/esm/axios.min.js +3 -0
  15. package/dist/esm/axios.min.js.map +1 -0
  16. package/dist/node/axios.cjs +5242 -0
  17. package/dist/node/axios.cjs.map +1 -0
  18. package/index.d.cts +572 -0
  19. package/index.d.ts +585 -0
  20. package/index.js +43 -0
  21. package/lib/adapters/README.md +37 -0
  22. package/lib/adapters/adapters.js +126 -0
  23. package/lib/adapters/fetch.js +288 -0
  24. package/lib/adapters/http.js +895 -0
  25. package/lib/adapters/xhr.js +200 -0
  26. package/lib/axios.js +89 -0
  27. package/lib/cancel/CancelToken.js +135 -0
  28. package/lib/cancel/CanceledError.js +25 -0
  29. package/lib/cancel/isCancel.js +5 -0
  30. package/lib/core/Axios.js +240 -0
  31. package/lib/core/AxiosError.js +110 -0
  32. package/lib/core/AxiosHeaders.js +314 -0
  33. package/lib/core/InterceptorManager.js +71 -0
  34. package/lib/core/README.md +8 -0
  35. package/lib/core/buildFullPath.js +22 -0
  36. package/lib/core/dispatchRequest.js +81 -0
  37. package/lib/core/mergeConfig.js +106 -0
  38. package/lib/core/settle.js +27 -0
  39. package/lib/core/transformData.js +28 -0
  40. package/lib/defaults/index.js +161 -0
  41. package/lib/defaults/transitional.js +7 -0
  42. package/lib/env/README.md +3 -0
  43. package/lib/env/classes/FormData.js +2 -0
  44. package/lib/env/data.js +1 -0
  45. package/lib/helpers/AxiosTransformStream.js +143 -0
  46. package/lib/helpers/AxiosURLSearchParams.js +58 -0
  47. package/lib/helpers/HttpStatusCode.js +77 -0
  48. package/lib/helpers/README.md +7 -0
  49. package/lib/helpers/ZlibHeaderTransformStream.js +28 -0
  50. package/lib/helpers/bind.js +14 -0
  51. package/lib/helpers/buildURL.js +67 -0
  52. package/lib/helpers/callbackify.js +16 -0
  53. package/lib/helpers/combineURLs.js +15 -0
  54. package/lib/helpers/composeSignals.js +48 -0
  55. package/lib/helpers/cookies.js +53 -0
  56. package/lib/helpers/deprecatedMethod.js +26 -0
  57. package/lib/helpers/estimateDataURLDecodedBytes.js +73 -0
  58. package/lib/helpers/formDataToJSON.js +95 -0
  59. package/lib/helpers/formDataToStream.js +112 -0
  60. package/lib/helpers/fromDataURI.js +53 -0
  61. package/lib/helpers/isAbsoluteURL.js +15 -0
  62. package/lib/helpers/isAxiosError.js +14 -0
  63. package/lib/helpers/isURLSameOrigin.js +14 -0
  64. package/lib/helpers/null.js +2 -0
  65. package/lib/helpers/parseHeaders.js +55 -0
  66. package/lib/helpers/parseProtocol.js +6 -0
  67. package/lib/helpers/progressEventReducer.js +44 -0
  68. package/lib/helpers/readBlob.js +15 -0
  69. package/lib/helpers/resolveConfig.js +61 -0
  70. package/lib/helpers/speedometer.js +55 -0
  71. package/lib/helpers/spread.js +28 -0
  72. package/lib/helpers/throttle.js +44 -0
  73. package/lib/helpers/toFormData.js +223 -0
  74. package/lib/helpers/toURLEncodedForm.js +19 -0
  75. package/lib/helpers/trackStream.js +87 -0
  76. package/lib/helpers/validator.js +99 -0
  77. package/lib/platform/browser/classes/Blob.js +3 -0
  78. package/lib/platform/browser/classes/FormData.js +3 -0
  79. package/lib/platform/browser/classes/URLSearchParams.js +4 -0
  80. package/lib/platform/browser/index.js +13 -0
  81. package/lib/platform/common/utils.js +51 -0
  82. package/lib/platform/index.js +7 -0
  83. package/lib/platform/node/classes/FormData.js +3 -0
  84. package/lib/platform/node/classes/URLSearchParams.js +4 -0
  85. package/lib/platform/node/index.js +38 -0
  86. package/lib/utils.js +782 -0
  87. package/package.json +237 -0
@@ -0,0 +1,48 @@
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
+ const {length} = (signals = signals ? signals.filter(Boolean) : []);
7
+
8
+ if (timeout || length) {
9
+ let controller = new AbortController();
10
+
11
+ let aborted;
12
+
13
+ const onabort = function (reason) {
14
+ if (!aborted) {
15
+ aborted = true;
16
+ unsubscribe();
17
+ const err = reason instanceof Error ? reason : this.reason;
18
+ controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
19
+ }
20
+ }
21
+
22
+ let timer = timeout && setTimeout(() => {
23
+ timer = null;
24
+ onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT))
25
+ }, timeout)
26
+
27
+ const unsubscribe = () => {
28
+ if (signals) {
29
+ timer && clearTimeout(timer);
30
+ timer = null;
31
+ signals.forEach(signal => {
32
+ signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
33
+ });
34
+ signals = null;
35
+ }
36
+ }
37
+
38
+ signals.forEach((signal) => signal.addEventListener('abort', onabort));
39
+
40
+ const {signal} = controller;
41
+
42
+ signal.unsubscribe = () => utils.asap(unsubscribe);
43
+
44
+ return signal;
45
+ }
46
+ }
47
+
48
+ export default composeSignals;
@@ -0,0 +1,53 @@
1
+ import utils from './../utils.js';
2
+ import platform from '../platform/index.js';
3
+
4
+ export default platform.hasStandardBrowserEnv ?
5
+
6
+ // Standard browser envs support document.cookie
7
+ {
8
+ write(name, value, expires, path, domain, secure, sameSite) {
9
+ if (typeof document === 'undefined') return;
10
+
11
+ const cookie = [`${name}=${encodeURIComponent(value)}`];
12
+
13
+ if (utils.isNumber(expires)) {
14
+ cookie.push(`expires=${new Date(expires).toUTCString()}`);
15
+ }
16
+ if (utils.isString(path)) {
17
+ cookie.push(`path=${path}`);
18
+ }
19
+ if (utils.isString(domain)) {
20
+ cookie.push(`domain=${domain}`);
21
+ }
22
+ if (secure === true) {
23
+ cookie.push('secure');
24
+ }
25
+ if (utils.isString(sameSite)) {
26
+ cookie.push(`SameSite=${sameSite}`);
27
+ }
28
+
29
+ document.cookie = cookie.join('; ');
30
+ },
31
+
32
+ read(name) {
33
+ if (typeof document === 'undefined') return null;
34
+ const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
35
+ return match ? decodeURIComponent(match[1]) : null;
36
+ },
37
+
38
+ remove(name) {
39
+ this.write(name, '', Date.now() - 86400000, '/');
40
+ }
41
+ }
42
+
43
+ :
44
+
45
+ // Non-standard browser env (web workers, react-native) lack needed support.
46
+ {
47
+ write() {},
48
+ read() {
49
+ return null;
50
+ },
51
+ remove() {}
52
+ };
53
+
@@ -0,0 +1,26 @@
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 `' + method + '`.' +
19
+ (instead ? ' Use `' + instead + '` instead.' : '') +
20
+ ' This method will be removed in a future release.');
21
+
22
+ if (docs) {
23
+ console.warn('For more information about usage see ' + docs);
24
+ }
25
+ } catch (e) { /* Ignore */ }
26
+ }
@@ -0,0 +1,73 @@
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
+ return Buffer.byteLength(body, 'utf8');
73
+ }
@@ -0,0 +1,95 @@
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] = [target[name], value];
62
+ } else {
63
+ target[name] = value;
64
+ }
65
+
66
+ return !isNumericKey;
67
+ }
68
+
69
+ if (!target[name] || !utils.isObject(target[name])) {
70
+ target[name] = [];
71
+ }
72
+
73
+ const result = buildPath(path, value, target[name], index);
74
+
75
+ if (result && utils.isArray(target[name])) {
76
+ target[name] = arrayToObject(target[name]);
77
+ }
78
+
79
+ return !isNumericKey;
80
+ }
81
+
82
+ if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
83
+ const obj = {};
84
+
85
+ utils.forEachEntry(formData, (name, value) => {
86
+ buildPath(parsePropPath(name), value, obj, 0);
87
+ });
88
+
89
+ return obj;
90
+ }
91
+
92
+ return null;
93
+ }
94
+
95
+ export default formDataToJSON;
@@ -0,0 +1,112 @@
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
+ headers += `Content-Type: ${value.type || "application/octet-stream"}${CRLF}`
28
+ }
29
+
30
+ this.headers = textEncoder.encode(headers + CRLF);
31
+
32
+ this.contentLength = isStringValue ? value.byteLength : value.size;
33
+
34
+ this.size = this.headers.byteLength + this.contentLength + CRLF_BYTES_COUNT;
35
+
36
+ this.name = name;
37
+ this.value = value;
38
+ }
39
+
40
+ async *encode(){
41
+ yield this.headers;
42
+
43
+ const {value} = this;
44
+
45
+ if(utils.isTypedArray(value)) {
46
+ yield value;
47
+ } else {
48
+ yield* readBlob(value);
49
+ }
50
+
51
+ yield CRLF_BYTES;
52
+ }
53
+
54
+ static escapeName(name) {
55
+ return String(name).replace(/[\r\n"]/g, (match) => ({
56
+ '\r' : '%0D',
57
+ '\n' : '%0A',
58
+ '"' : '%22',
59
+ }[match]));
60
+ }
61
+ }
62
+
63
+ const formDataToStream = (form, headersHandler, options) => {
64
+ const {
65
+ tag = 'form-data-boundary',
66
+ size = 25,
67
+ boundary = tag + '-' + platform.generateString(size, BOUNDARY_ALPHABET)
68
+ } = options || {};
69
+
70
+ if(!utils.isFormData(form)) {
71
+ throw TypeError('FormData instance required');
72
+ }
73
+
74
+ if (boundary.length < 1 || boundary.length > 70) {
75
+ throw Error('boundary must be 10-70 characters long')
76
+ }
77
+
78
+ const boundaryBytes = textEncoder.encode('--' + boundary + CRLF);
79
+ const footerBytes = textEncoder.encode('--' + boundary + '--' + CRLF);
80
+ let contentLength = footerBytes.byteLength;
81
+
82
+ const parts = Array.from(form.entries()).map(([name, value]) => {
83
+ const part = new FormDataPart(name, value);
84
+ contentLength += part.size;
85
+ return part;
86
+ });
87
+
88
+ contentLength += boundaryBytes.byteLength * parts.length;
89
+
90
+ contentLength = utils.toFiniteNumber(contentLength);
91
+
92
+ const computedHeaders = {
93
+ 'Content-Type': `multipart/form-data; boundary=${boundary}`
94
+ }
95
+
96
+ if (Number.isFinite(contentLength)) {
97
+ computedHeaders['Content-Length'] = contentLength;
98
+ }
99
+
100
+ headersHandler && headersHandler(computedHeaders);
101
+
102
+ return Readable.from((async function *() {
103
+ for(const part of parts) {
104
+ yield boundaryBytes;
105
+ yield* part.encode();
106
+ }
107
+
108
+ yield footerBytes;
109
+ })());
110
+ };
111
+
112
+ export default formDataToStream;
@@ -0,0 +1,53 @@
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
+ const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
8
+
9
+ /**
10
+ * Parse data uri to a Buffer or Blob
11
+ *
12
+ * @param {String} uri
13
+ * @param {?Boolean} asBlob
14
+ * @param {?Object} options
15
+ * @param {?Function} options.Blob
16
+ *
17
+ * @returns {Buffer|Blob}
18
+ */
19
+ export default function fromDataURI(uri, asBlob, options) {
20
+ const _Blob = options && options.Blob || platform.classes.Blob;
21
+ const protocol = parseProtocol(uri);
22
+
23
+ if (asBlob === undefined && _Blob) {
24
+ asBlob = true;
25
+ }
26
+
27
+ if (protocol === 'data') {
28
+ uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
29
+
30
+ const match = DATA_URL_PATTERN.exec(uri);
31
+
32
+ if (!match) {
33
+ throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
34
+ }
35
+
36
+ const mime = match[1];
37
+ const isBase64 = match[2];
38
+ const body = match[3];
39
+ const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8');
40
+
41
+ if (asBlob) {
42
+ if (!_Blob) {
43
+ throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
44
+ }
45
+
46
+ return new _Blob([buffer], {type: mime});
47
+ }
48
+
49
+ return buffer;
50
+ }
51
+
52
+ throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
53
+ }
@@ -0,0 +1,15 @@
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
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
15
+ }
@@ -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,14 @@
1
+ import platform from '../platform/index.js';
2
+
3
+ export default platform.hasStandardBrowserEnv ? ((origin, isMSIE) => (url) => {
4
+ url = new URL(url, platform.origin);
5
+
6
+ return (
7
+ origin.protocol === url.protocol &&
8
+ origin.host === url.host &&
9
+ (isMSIE || origin.port === url.port)
10
+ );
11
+ })(
12
+ new URL(platform.origin),
13
+ platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)
14
+ ) : () => true;
@@ -0,0 +1,2 @@
1
+ // eslint-disable-next-line strict
2
+ export default null;
@@ -0,0 +1,55 @@
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', 'authorization', 'content-length', 'content-type', 'etag',
9
+ 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
10
+ 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
11
+ 'referer', 'retry-after', 'user-agent'
12
+ ]);
13
+
14
+ /**
15
+ * Parse headers into an object
16
+ *
17
+ * ```
18
+ * Date: Wed, 27 Aug 2014 08:58:49 GMT
19
+ * Content-Type: application/json
20
+ * Connection: keep-alive
21
+ * Transfer-Encoding: chunked
22
+ * ```
23
+ *
24
+ * @param {String} rawHeaders Headers needing to be parsed
25
+ *
26
+ * @returns {Object} Headers parsed into an object
27
+ */
28
+ export default rawHeaders => {
29
+ const parsed = {};
30
+ let key;
31
+ let val;
32
+ let i;
33
+
34
+ rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
35
+ i = line.indexOf(':');
36
+ key = line.substring(0, i).trim().toLowerCase();
37
+ val = line.substring(i + 1).trim();
38
+
39
+ if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
40
+ return;
41
+ }
42
+
43
+ if (key === 'set-cookie') {
44
+ if (parsed[key]) {
45
+ parsed[key].push(val);
46
+ } else {
47
+ parsed[key] = [val];
48
+ }
49
+ } else {
50
+ parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
51
+ }
52
+ });
53
+
54
+ return parsed;
55
+ };
@@ -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
+ }
@@ -0,0 +1,44 @@
1
+ import speedometer from "./speedometer.js";
2
+ import throttle from "./throttle.js";
3
+ import utils from "../utils.js";
4
+
5
+ export const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
6
+ let bytesNotified = 0;
7
+ const _speedometer = speedometer(50, 250);
8
+
9
+ return throttle(e => {
10
+ const loaded = e.loaded;
11
+ const total = e.lengthComputable ? e.total : undefined;
12
+ const progressBytes = loaded - bytesNotified;
13
+ const rate = _speedometer(progressBytes);
14
+ const inRange = loaded <= total;
15
+
16
+ bytesNotified = loaded;
17
+
18
+ const data = {
19
+ loaded,
20
+ total,
21
+ progress: total ? (loaded / total) : undefined,
22
+ bytes: progressBytes,
23
+ rate: rate ? rate : undefined,
24
+ estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
25
+ event: e,
26
+ lengthComputable: total != null,
27
+ [isDownloadStream ? 'download' : 'upload']: true
28
+ };
29
+
30
+ listener(data);
31
+ }, freq);
32
+ }
33
+
34
+ export const progressEventDecorator = (total, throttled) => {
35
+ const lengthComputable = total != null;
36
+
37
+ return [(loaded) => throttled[0]({
38
+ lengthComputable,
39
+ total,
40
+ loaded
41
+ }), throttled[1]];
42
+ }
43
+
44
+ export const asyncDecorator = (fn) => (...args) => utils.asap(() => fn(...args));
@@ -0,0 +1,15 @@
1
+ const {asyncIterator} = Symbol;
2
+
3
+ const readBlob = async function* (blob) {
4
+ if (blob.stream) {
5
+ yield* blob.stream()
6
+ } else if (blob.arrayBuffer) {
7
+ yield await blob.arrayBuffer()
8
+ } else if (blob[asyncIterator]) {
9
+ yield* blob[asyncIterator]();
10
+ } else {
11
+ yield blob;
12
+ }
13
+ }
14
+
15
+ export default readBlob;