axios 1.0.0-alpha.1 → 1.1.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.
Potentially problematic release.
This version of axios might be problematic. Click here for more details.
- package/CHANGELOG.md +74 -1
- package/README.md +59 -48
- package/SECURITY.md +3 -2
- package/bin/ssl_hotfix.js +1 -1
- package/dist/axios.js +1564 -981
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/esm/axios.js +1472 -866
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +3761 -0
- package/dist/node/axios.cjs.map +1 -0
- package/gulpfile.js +88 -0
- package/index.d.ts +213 -67
- package/index.js +2 -1
- package/karma.conf.cjs +250 -0
- package/lib/adapters/http.js +256 -131
- package/lib/adapters/index.js +33 -0
- package/lib/adapters/xhr.js +79 -56
- package/lib/axios.js +41 -25
- package/lib/cancel/CancelToken.js +91 -88
- package/lib/cancel/CanceledError.js +5 -4
- package/lib/cancel/isCancel.js +2 -2
- package/lib/core/Axios.js +127 -100
- package/lib/core/AxiosError.js +10 -7
- package/lib/core/AxiosHeaders.js +274 -0
- package/lib/core/InterceptorManager.js +61 -53
- package/lib/core/buildFullPath.js +5 -4
- package/lib/core/dispatchRequest.js +21 -39
- package/lib/core/mergeConfig.js +8 -7
- package/lib/core/settle.js +6 -4
- package/lib/core/transformData.js +15 -10
- package/lib/defaults/index.js +46 -39
- package/lib/defaults/transitional.js +1 -1
- package/lib/env/classes/FormData.js +2 -2
- package/lib/env/data.js +1 -3
- package/lib/helpers/AxiosTransformStream.js +191 -0
- package/lib/helpers/AxiosURLSearchParams.js +23 -7
- package/lib/helpers/bind.js +2 -2
- package/lib/helpers/buildURL.js +16 -7
- package/lib/helpers/combineURLs.js +3 -2
- package/lib/helpers/cookies.js +43 -44
- package/lib/helpers/deprecatedMethod.js +4 -2
- package/lib/helpers/formDataToJSON.js +36 -15
- package/lib/helpers/fromDataURI.js +15 -13
- package/lib/helpers/isAbsoluteURL.js +3 -2
- package/lib/helpers/isAxiosError.js +4 -3
- package/lib/helpers/isURLSameOrigin.js +55 -56
- package/lib/helpers/null.js +1 -1
- package/lib/helpers/parseHeaders.js +24 -22
- package/lib/helpers/parseProtocol.js +3 -3
- package/lib/helpers/speedometer.js +55 -0
- package/lib/helpers/spread.js +3 -2
- package/lib/helpers/throttle.js +33 -0
- package/lib/helpers/toFormData.js +68 -18
- package/lib/helpers/toURLEncodedForm.js +5 -5
- package/lib/helpers/validator.js +20 -15
- package/lib/platform/browser/classes/FormData.js +1 -1
- package/lib/platform/browser/classes/URLSearchParams.js +2 -3
- package/lib/platform/browser/index.js +38 -6
- package/lib/platform/index.js +2 -2
- package/lib/platform/node/classes/FormData.js +2 -2
- package/lib/platform/node/classes/URLSearchParams.js +2 -3
- package/lib/platform/node/index.js +5 -4
- package/lib/utils.js +294 -192
- package/package.json +55 -22
- package/rollup.config.js +37 -7
- package/lib/helpers/normalizeHeaderName.js +0 -12
@@ -0,0 +1,191 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
import stream from 'stream';
|
4
|
+
import utils from '../utils.js';
|
5
|
+
import throttle from './throttle.js';
|
6
|
+
import speedometer from './speedometer.js';
|
7
|
+
|
8
|
+
const kInternals = Symbol('internals');
|
9
|
+
|
10
|
+
class AxiosTransformStream extends stream.Transform{
|
11
|
+
constructor(options) {
|
12
|
+
options = utils.toFlatObject(options, {
|
13
|
+
maxRate: 0,
|
14
|
+
chunkSize: 64 * 1024,
|
15
|
+
minChunkSize: 100,
|
16
|
+
timeWindow: 500,
|
17
|
+
ticksRate: 2,
|
18
|
+
samplesCount: 15
|
19
|
+
}, null, (prop, source) => {
|
20
|
+
return !utils.isUndefined(source[prop]);
|
21
|
+
});
|
22
|
+
|
23
|
+
super({
|
24
|
+
readableHighWaterMark: options.chunkSize
|
25
|
+
});
|
26
|
+
|
27
|
+
const self = this;
|
28
|
+
|
29
|
+
const internals = this[kInternals] = {
|
30
|
+
length: options.length,
|
31
|
+
timeWindow: options.timeWindow,
|
32
|
+
ticksRate: options.ticksRate,
|
33
|
+
chunkSize: options.chunkSize,
|
34
|
+
maxRate: options.maxRate,
|
35
|
+
minChunkSize: options.minChunkSize,
|
36
|
+
bytesSeen: 0,
|
37
|
+
isCaptured: false,
|
38
|
+
notifiedBytesLoaded: 0,
|
39
|
+
ts: Date.now(),
|
40
|
+
bytes: 0,
|
41
|
+
onReadCallback: null
|
42
|
+
};
|
43
|
+
|
44
|
+
const _speedometer = speedometer(internals.ticksRate * options.samplesCount, internals.timeWindow);
|
45
|
+
|
46
|
+
this.on('newListener', event => {
|
47
|
+
if (event === 'progress') {
|
48
|
+
if (!internals.isCaptured) {
|
49
|
+
internals.isCaptured = true;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
});
|
53
|
+
|
54
|
+
let bytesNotified = 0;
|
55
|
+
|
56
|
+
internals.updateProgress = throttle(function throttledHandler() {
|
57
|
+
const totalBytes = internals.length;
|
58
|
+
const bytesTransferred = internals.bytesSeen;
|
59
|
+
const progressBytes = bytesTransferred - bytesNotified;
|
60
|
+
if (!progressBytes || self.destroyed) return;
|
61
|
+
|
62
|
+
const rate = _speedometer(progressBytes);
|
63
|
+
|
64
|
+
bytesNotified = bytesTransferred;
|
65
|
+
|
66
|
+
process.nextTick(() => {
|
67
|
+
self.emit('progress', {
|
68
|
+
'loaded': bytesTransferred,
|
69
|
+
'total': totalBytes,
|
70
|
+
'progress': totalBytes ? (bytesTransferred / totalBytes) : undefined,
|
71
|
+
'bytes': progressBytes,
|
72
|
+
'rate': rate ? rate : undefined,
|
73
|
+
'estimated': rate && totalBytes && bytesTransferred <= totalBytes ?
|
74
|
+
(totalBytes - bytesTransferred) / rate : undefined
|
75
|
+
});
|
76
|
+
});
|
77
|
+
}, internals.ticksRate);
|
78
|
+
|
79
|
+
const onFinish = () => {
|
80
|
+
internals.updateProgress(true);
|
81
|
+
};
|
82
|
+
|
83
|
+
this.once('end', onFinish);
|
84
|
+
this.once('error', onFinish);
|
85
|
+
}
|
86
|
+
|
87
|
+
_read(size) {
|
88
|
+
const internals = this[kInternals];
|
89
|
+
|
90
|
+
if (internals.onReadCallback) {
|
91
|
+
internals.onReadCallback();
|
92
|
+
}
|
93
|
+
|
94
|
+
return super._read(size);
|
95
|
+
}
|
96
|
+
|
97
|
+
_transform(chunk, encoding, callback) {
|
98
|
+
const self = this;
|
99
|
+
const internals = this[kInternals];
|
100
|
+
const maxRate = internals.maxRate;
|
101
|
+
|
102
|
+
const readableHighWaterMark = this.readableHighWaterMark;
|
103
|
+
|
104
|
+
const timeWindow = internals.timeWindow;
|
105
|
+
|
106
|
+
const divider = 1000 / timeWindow;
|
107
|
+
const bytesThreshold = (maxRate / divider);
|
108
|
+
const minChunkSize = internals.minChunkSize !== false ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) : 0;
|
109
|
+
|
110
|
+
function pushChunk(_chunk, _callback) {
|
111
|
+
const bytes = Buffer.byteLength(_chunk);
|
112
|
+
internals.bytesSeen += bytes;
|
113
|
+
internals.bytes += bytes;
|
114
|
+
|
115
|
+
if (internals.isCaptured) {
|
116
|
+
internals.updateProgress();
|
117
|
+
}
|
118
|
+
|
119
|
+
if (self.push(_chunk)) {
|
120
|
+
process.nextTick(_callback);
|
121
|
+
} else {
|
122
|
+
internals.onReadCallback = () => {
|
123
|
+
internals.onReadCallback = null;
|
124
|
+
process.nextTick(_callback);
|
125
|
+
};
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
const transformChunk = (_chunk, _callback) => {
|
130
|
+
const chunkSize = Buffer.byteLength(_chunk);
|
131
|
+
let chunkRemainder = null;
|
132
|
+
let maxChunkSize = readableHighWaterMark;
|
133
|
+
let bytesLeft;
|
134
|
+
let passed = 0;
|
135
|
+
|
136
|
+
if (maxRate) {
|
137
|
+
const now = Date.now();
|
138
|
+
|
139
|
+
if (!internals.ts || (passed = (now - internals.ts)) >= timeWindow) {
|
140
|
+
internals.ts = now;
|
141
|
+
bytesLeft = bytesThreshold - internals.bytes;
|
142
|
+
internals.bytes = bytesLeft < 0 ? -bytesLeft : 0;
|
143
|
+
passed = 0;
|
144
|
+
}
|
145
|
+
|
146
|
+
bytesLeft = bytesThreshold - internals.bytes;
|
147
|
+
}
|
148
|
+
|
149
|
+
if (maxRate) {
|
150
|
+
if (bytesLeft <= 0) {
|
151
|
+
// next time window
|
152
|
+
return setTimeout(() => {
|
153
|
+
_callback(null, _chunk);
|
154
|
+
}, timeWindow - passed);
|
155
|
+
}
|
156
|
+
|
157
|
+
if (bytesLeft < maxChunkSize) {
|
158
|
+
maxChunkSize = bytesLeft;
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
if (maxChunkSize && chunkSize > maxChunkSize && (chunkSize - maxChunkSize) > minChunkSize) {
|
163
|
+
chunkRemainder = _chunk.subarray(maxChunkSize);
|
164
|
+
_chunk = _chunk.subarray(0, maxChunkSize);
|
165
|
+
}
|
166
|
+
|
167
|
+
pushChunk(_chunk, chunkRemainder ? () => {
|
168
|
+
process.nextTick(_callback, null, chunkRemainder);
|
169
|
+
} : _callback);
|
170
|
+
};
|
171
|
+
|
172
|
+
transformChunk(chunk, function transformNextChunk(err, _chunk) {
|
173
|
+
if (err) {
|
174
|
+
return callback(err);
|
175
|
+
}
|
176
|
+
|
177
|
+
if (_chunk) {
|
178
|
+
transformChunk(_chunk, transformNextChunk);
|
179
|
+
} else {
|
180
|
+
callback(null);
|
181
|
+
}
|
182
|
+
});
|
183
|
+
}
|
184
|
+
|
185
|
+
setLength(length) {
|
186
|
+
this[kInternals].length = +length;
|
187
|
+
return this;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
export default AxiosTransformStream;
|
@@ -1,9 +1,17 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
import toFormData from './toFormData.js';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* It encodes a string by replacing all characters that are not in the unreserved set with
|
7
|
+
* their percent-encoded equivalents
|
8
|
+
*
|
9
|
+
* @param {string} str - The string to encode.
|
10
|
+
*
|
11
|
+
* @returns {string} The encoded string.
|
12
|
+
*/
|
5
13
|
function encode(str) {
|
6
|
-
|
14
|
+
const charMap = {
|
7
15
|
'!': '%21',
|
8
16
|
"'": '%27',
|
9
17
|
'(': '%28',
|
@@ -12,25 +20,33 @@ function encode(str) {
|
|
12
20
|
'%20': '+',
|
13
21
|
'%00': '\x00'
|
14
22
|
};
|
15
|
-
return encodeURIComponent(str).replace(/[!'
|
23
|
+
return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
|
16
24
|
return charMap[match];
|
17
25
|
});
|
18
26
|
}
|
19
27
|
|
28
|
+
/**
|
29
|
+
* It takes a params object and converts it to a FormData object
|
30
|
+
*
|
31
|
+
* @param {Object<string, any>} params - The parameters to be converted to a FormData object.
|
32
|
+
* @param {Object<string, any>} options - The options object passed to the Axios constructor.
|
33
|
+
*
|
34
|
+
* @returns {void}
|
35
|
+
*/
|
20
36
|
function AxiosURLSearchParams(params, options) {
|
21
37
|
this._pairs = [];
|
22
38
|
|
23
39
|
params && toFormData(params, this, options);
|
24
40
|
}
|
25
41
|
|
26
|
-
|
42
|
+
const prototype = AxiosURLSearchParams.prototype;
|
27
43
|
|
28
44
|
prototype.append = function append(name, value) {
|
29
45
|
this._pairs.push([name, value]);
|
30
46
|
};
|
31
47
|
|
32
48
|
prototype.toString = function toString(encoder) {
|
33
|
-
|
49
|
+
const _encode = encoder ? function(value) {
|
34
50
|
return encoder.call(this, value, encode);
|
35
51
|
} : encode;
|
36
52
|
|
@@ -39,4 +55,4 @@ prototype.toString = function toString(encoder) {
|
|
39
55
|
}, '').join('&');
|
40
56
|
};
|
41
57
|
|
42
|
-
|
58
|
+
export default AxiosURLSearchParams;
|
package/lib/helpers/bind.js
CHANGED
package/lib/helpers/buildURL.js
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
import utils from '../utils.js';
|
4
|
+
import AxiosURLSearchParams from '../helpers/AxiosURLSearchParams.js';
|
5
5
|
|
6
|
+
/**
|
7
|
+
* It replaces all instances of the characters `:`, `$`, `,`, `+`, `[`, and `]` with their
|
8
|
+
* URI encoded counterparts
|
9
|
+
*
|
10
|
+
* @param {string} val The value to be encoded.
|
11
|
+
*
|
12
|
+
* @returns {string} The encoded value.
|
13
|
+
*/
|
6
14
|
function encode(val) {
|
7
15
|
return encodeURIComponent(val).
|
8
16
|
replace(/%3A/gi, ':').
|
@@ -19,23 +27,24 @@ function encode(val) {
|
|
19
27
|
* @param {string} url The base of the url (e.g., http://www.google.com)
|
20
28
|
* @param {object} [params] The params to be appended
|
21
29
|
* @param {?object} options
|
30
|
+
*
|
22
31
|
* @returns {string} The formatted url
|
23
32
|
*/
|
24
|
-
|
33
|
+
export default function buildURL(url, params, options) {
|
25
34
|
/*eslint no-param-reassign:0*/
|
26
35
|
if (!params) {
|
27
36
|
return url;
|
28
37
|
}
|
29
38
|
|
30
|
-
|
39
|
+
const hashmarkIndex = url.indexOf('#');
|
31
40
|
|
32
41
|
if (hashmarkIndex !== -1) {
|
33
42
|
url = url.slice(0, hashmarkIndex);
|
34
43
|
}
|
35
44
|
|
36
|
-
|
45
|
+
const _encode = options && options.encode || encode;
|
37
46
|
|
38
|
-
|
47
|
+
const serializerParams = utils.isURLSearchParams(params) ?
|
39
48
|
params.toString() :
|
40
49
|
new AxiosURLSearchParams(params, options).toString(_encode);
|
41
50
|
|
@@ -44,4 +53,4 @@ module.exports = function buildURL(url, params, options) {
|
|
44
53
|
}
|
45
54
|
|
46
55
|
return url;
|
47
|
-
}
|
56
|
+
}
|
@@ -5,10 +5,11 @@
|
|
5
5
|
*
|
6
6
|
* @param {string} baseURL The base URL
|
7
7
|
* @param {string} relativeURL The relative URL
|
8
|
+
*
|
8
9
|
* @returns {string} The combined URL
|
9
10
|
*/
|
10
|
-
|
11
|
+
export default function combineURLs(baseURL, relativeURL) {
|
11
12
|
return relativeURL
|
12
13
|
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
13
14
|
: baseURL;
|
14
|
-
}
|
15
|
+
}
|
package/lib/helpers/cookies.js
CHANGED
@@ -1,53 +1,52 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
3
|
+
import utils from './../utils.js';
|
4
|
+
import platform from '../platform/index.js';
|
4
5
|
|
5
|
-
|
6
|
-
utils.isStandardBrowserEnv() ?
|
6
|
+
export default platform.isStandardBrowserEnv ?
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
// Standard browser envs support document.cookie
|
9
|
+
(function standardBrowserEnv() {
|
10
|
+
return {
|
11
|
+
write: function write(name, value, expires, path, domain, secure) {
|
12
|
+
const cookie = [];
|
13
|
+
cookie.push(name + '=' + encodeURIComponent(value));
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
if (utils.isString(path)) {
|
20
|
-
cookie.push('path=' + path);
|
21
|
-
}
|
22
|
-
|
23
|
-
if (utils.isString(domain)) {
|
24
|
-
cookie.push('domain=' + domain);
|
25
|
-
}
|
26
|
-
|
27
|
-
if (secure === true) {
|
28
|
-
cookie.push('secure');
|
29
|
-
}
|
15
|
+
if (utils.isNumber(expires)) {
|
16
|
+
cookie.push('expires=' + new Date(expires).toGMTString());
|
17
|
+
}
|
30
18
|
|
31
|
-
|
32
|
-
|
19
|
+
if (utils.isString(path)) {
|
20
|
+
cookie.push('path=' + path);
|
21
|
+
}
|
33
22
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
},
|
23
|
+
if (utils.isString(domain)) {
|
24
|
+
cookie.push('domain=' + domain);
|
25
|
+
}
|
38
26
|
|
39
|
-
|
40
|
-
|
27
|
+
if (secure === true) {
|
28
|
+
cookie.push('secure');
|
41
29
|
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
30
|
+
|
31
|
+
document.cookie = cookie.join('; ');
|
32
|
+
},
|
33
|
+
|
34
|
+
read: function read(name) {
|
35
|
+
const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
36
|
+
return (match ? decodeURIComponent(match[3]) : null);
|
37
|
+
},
|
38
|
+
|
39
|
+
remove: function remove(name) {
|
40
|
+
this.write(name, '', Date.now() - 86400000);
|
41
|
+
}
|
42
|
+
};
|
43
|
+
})() :
|
44
|
+
|
45
|
+
// Non standard browser env (web workers, react-native) lack needed support.
|
46
|
+
(function nonStandardBrowserEnv() {
|
47
|
+
return {
|
48
|
+
write: function write() {},
|
49
|
+
read: function read() { return null; },
|
50
|
+
remove: function remove() {}
|
51
|
+
};
|
52
|
+
})();
|
@@ -9,8 +9,10 @@
|
|
9
9
|
* @param {string} method The name of the deprecated method
|
10
10
|
* @param {string} [instead] The alternate method to use if applicable
|
11
11
|
* @param {string} [docs] The documentation URL to get further details
|
12
|
+
*
|
13
|
+
* @returns {void}
|
12
14
|
*/
|
13
|
-
|
15
|
+
export default function deprecatedMethod(method, instead, docs) {
|
14
16
|
try {
|
15
17
|
console.warn(
|
16
18
|
'DEPRECATED method `' + method + '`.' +
|
@@ -21,4 +23,4 @@ module.exports = function deprecatedMethod(method, instead, docs) {
|
|
21
23
|
console.warn('For more information about usage see ' + docs);
|
22
24
|
}
|
23
25
|
} catch (e) { /* Ignore */ }
|
24
|
-
}
|
26
|
+
}
|
@@ -1,23 +1,37 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
3
|
+
import utils from '../utils.js';
|
4
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
|
+
*/
|
5
12
|
function parsePropPath(name) {
|
6
13
|
// foo[x][y][z]
|
7
14
|
// foo.x.y.z
|
8
15
|
// foo-x-y-z
|
9
16
|
// foo x y z
|
10
|
-
return utils.matchAll(/\w+|\[(\w*)]/g, name).map(
|
17
|
+
return utils.matchAll(/\w+|\[(\w*)]/g, name).map(match => {
|
11
18
|
return match[0] === '[]' ? '' : match[1] || match[0];
|
12
19
|
});
|
13
20
|
}
|
14
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
|
+
*/
|
15
29
|
function arrayToObject(arr) {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
30
|
+
const obj = {};
|
31
|
+
const keys = Object.keys(arr);
|
32
|
+
let i;
|
33
|
+
const len = keys.length;
|
34
|
+
let key;
|
21
35
|
for (i = 0; i < len; i++) {
|
22
36
|
key = keys[i];
|
23
37
|
obj[key] = arr[key];
|
@@ -25,15 +39,22 @@ function arrayToObject(arr) {
|
|
25
39
|
return obj;
|
26
40
|
}
|
27
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
|
+
*/
|
28
49
|
function formDataToJSON(formData) {
|
29
50
|
function buildPath(path, value, target, index) {
|
30
|
-
|
31
|
-
|
32
|
-
|
51
|
+
let name = path[index++];
|
52
|
+
const isNumericKey = Number.isFinite(+name);
|
53
|
+
const isLast = index >= path.length;
|
33
54
|
name = !name && utils.isArray(target) ? target.length : name;
|
34
55
|
|
35
56
|
if (isLast) {
|
36
|
-
if (utils.
|
57
|
+
if (utils.hasOwnProp(target, name)) {
|
37
58
|
target[name] = [target[name], value];
|
38
59
|
} else {
|
39
60
|
target[name] = value;
|
@@ -46,7 +67,7 @@ function formDataToJSON(formData) {
|
|
46
67
|
target[name] = [];
|
47
68
|
}
|
48
69
|
|
49
|
-
|
70
|
+
const result = buildPath(path, value, target[name], index);
|
50
71
|
|
51
72
|
if (result && utils.isArray(target[name])) {
|
52
73
|
target[name] = arrayToObject(target[name]);
|
@@ -56,9 +77,9 @@ function formDataToJSON(formData) {
|
|
56
77
|
}
|
57
78
|
|
58
79
|
if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
|
59
|
-
|
80
|
+
const obj = {};
|
60
81
|
|
61
|
-
utils.forEachEntry(formData,
|
82
|
+
utils.forEachEntry(formData, (name, value) => {
|
62
83
|
buildPath(parsePropPath(name), value, obj, 0);
|
63
84
|
});
|
64
85
|
|
@@ -68,4 +89,4 @@ function formDataToJSON(formData) {
|
|
68
89
|
return null;
|
69
90
|
}
|
70
91
|
|
71
|
-
|
92
|
+
export default formDataToJSON;
|
@@ -1,22 +1,24 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
import AxiosError from '../core/AxiosError.js';
|
4
|
+
import parseProtocol from './parseProtocol.js';
|
5
|
+
import platform from '../platform/index.js';
|
6
6
|
|
7
|
-
|
7
|
+
const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
|
8
8
|
|
9
9
|
/**
|
10
10
|
* Parse data uri to a Buffer or Blob
|
11
|
+
*
|
11
12
|
* @param {String} uri
|
12
13
|
* @param {?Boolean} asBlob
|
13
14
|
* @param {?Object} options
|
14
15
|
* @param {?Function} options.Blob
|
16
|
+
*
|
15
17
|
* @returns {Buffer|Blob}
|
16
18
|
*/
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
export default function fromDataURI(uri, asBlob, options) {
|
20
|
+
const _Blob = options && options.Blob || platform.classes.Blob;
|
21
|
+
const protocol = parseProtocol(uri);
|
20
22
|
|
21
23
|
if (asBlob === undefined && _Blob) {
|
22
24
|
asBlob = true;
|
@@ -25,16 +27,16 @@ module.exports = function fromDataURI(uri, asBlob, options) {
|
|
25
27
|
if (protocol === 'data') {
|
26
28
|
uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
|
27
29
|
|
28
|
-
|
30
|
+
const match = DATA_URL_PATTERN.exec(uri);
|
29
31
|
|
30
32
|
if (!match) {
|
31
33
|
throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
|
32
34
|
}
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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');
|
38
40
|
|
39
41
|
if (asBlob) {
|
40
42
|
if (!_Blob) {
|
@@ -48,4 +50,4 @@ module.exports = function fromDataURI(uri, asBlob, options) {
|
|
48
50
|
}
|
49
51
|
|
50
52
|
throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
|
51
|
-
}
|
53
|
+
}
|
@@ -4,11 +4,12 @@
|
|
4
4
|
* Determines whether the specified URL is absolute
|
5
5
|
*
|
6
6
|
* @param {string} url The URL to test
|
7
|
+
*
|
7
8
|
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
8
9
|
*/
|
9
|
-
|
10
|
+
export default function isAbsoluteURL(url) {
|
10
11
|
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
11
12
|
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
12
13
|
// by any combination of letters, digits, plus, period, or hyphen.
|
13
14
|
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
14
|
-
}
|
15
|
+
}
|
@@ -1,13 +1,14 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
3
|
+
import utils from './../utils.js';
|
4
4
|
|
5
5
|
/**
|
6
6
|
* Determines whether the payload is an error thrown by Axios
|
7
7
|
*
|
8
8
|
* @param {*} payload The value to test
|
9
|
+
*
|
9
10
|
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
10
11
|
*/
|
11
|
-
|
12
|
+
export default function isAxiosError(payload) {
|
12
13
|
return utils.isObject(payload) && (payload.isAxiosError === true);
|
13
|
-
}
|
14
|
+
}
|