axios 1.2.0-alpha.1 → 1.2.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 +17 -1
- package/README.md +4 -2
- package/dist/axios.js +424 -391
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +430 -386
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +430 -386
- 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 +404 -361
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.ts +5 -1
- package/lib/adapters/adapters.js +59 -0
- package/lib/adapters/http.js +21 -19
- package/lib/adapters/xhr.js +3 -1
- package/lib/core/AxiosError.js +1 -1
- package/lib/core/dispatchRequest.js +2 -1
- package/lib/defaults/index.js +1 -20
- package/lib/env/data.js +1 -1
- package/lib/utils.js +33 -1
- package/package.json +2 -2
- package/lib/adapters/index.js +0 -33
package/index.d.ts
CHANGED
@@ -277,6 +277,10 @@ export interface AxiosProgressEvent {
|
|
277
277
|
|
278
278
|
type Milliseconds = number;
|
279
279
|
|
280
|
+
type AxiosAdapterName = 'xhr' | 'http' | string;
|
281
|
+
|
282
|
+
type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
|
283
|
+
|
280
284
|
export interface AxiosRequestConfig<D = any> {
|
281
285
|
url?: string;
|
282
286
|
method?: Method | string;
|
@@ -290,7 +294,7 @@ export interface AxiosRequestConfig<D = any> {
|
|
290
294
|
timeout?: Milliseconds;
|
291
295
|
timeoutErrorMessage?: string;
|
292
296
|
withCredentials?: boolean;
|
293
|
-
adapter?:
|
297
|
+
adapter?: AxiosAdapterConfig | AxiosAdapterConfig[];
|
294
298
|
auth?: AxiosBasicCredentials;
|
295
299
|
responseType?: ResponseType;
|
296
300
|
responseEncoding?: responseEncoding | string;
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import utils from '../utils.js';
|
2
|
+
import httpAdapter from './http.js';
|
3
|
+
import xhrAdapter from './xhr.js';
|
4
|
+
import AxiosError from "../core/AxiosError.js";
|
5
|
+
|
6
|
+
const knownAdapters = {
|
7
|
+
http: httpAdapter,
|
8
|
+
xhr: xhrAdapter
|
9
|
+
}
|
10
|
+
|
11
|
+
utils.forEach(knownAdapters, (fn, value) => {
|
12
|
+
if(fn) {
|
13
|
+
try {
|
14
|
+
Object.defineProperty(fn, 'name', {value});
|
15
|
+
} catch (e) {
|
16
|
+
// eslint-disable-next-line no-empty
|
17
|
+
}
|
18
|
+
Object.defineProperty(fn, 'adapterName', {value});
|
19
|
+
}
|
20
|
+
});
|
21
|
+
|
22
|
+
export default {
|
23
|
+
getAdapter: (adapters) => {
|
24
|
+
adapters = utils.isArray(adapters) ? adapters : [adapters];
|
25
|
+
|
26
|
+
const {length} = adapters;
|
27
|
+
let nameOrAdapter;
|
28
|
+
let adapter;
|
29
|
+
|
30
|
+
for (let i = 0; i < length; i++) {
|
31
|
+
nameOrAdapter = adapters[i];
|
32
|
+
if((adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter)) {
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
if (!adapter) {
|
38
|
+
if (adapter === false) {
|
39
|
+
throw new AxiosError(
|
40
|
+
`Adapter ${nameOrAdapter} is not supported by the environment`,
|
41
|
+
'ERR_NOT_SUPPORT'
|
42
|
+
);
|
43
|
+
}
|
44
|
+
|
45
|
+
throw new Error(
|
46
|
+
utils.hasOwnProp(knownAdapters, nameOrAdapter) ?
|
47
|
+
`Adapter '${nameOrAdapter}' is not available in the build` :
|
48
|
+
`Unknown adapter '${nameOrAdapter}'`
|
49
|
+
);
|
50
|
+
}
|
51
|
+
|
52
|
+
if (!utils.isFunction(adapter)) {
|
53
|
+
throw new TypeError('adapter is not a function');
|
54
|
+
}
|
55
|
+
|
56
|
+
return adapter;
|
57
|
+
},
|
58
|
+
adapters: knownAdapters
|
59
|
+
}
|
package/lib/adapters/http.js
CHANGED
@@ -100,8 +100,10 @@ function setProxy(options, configProxy, location) {
|
|
100
100
|
};
|
101
101
|
}
|
102
102
|
|
103
|
+
const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(process) === 'process';
|
104
|
+
|
103
105
|
/*eslint consistent-return:0*/
|
104
|
-
export default function httpAdapter(config) {
|
106
|
+
export default isHttpAdapterSupported && function httpAdapter(config) {
|
105
107
|
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
|
106
108
|
let data = config.data;
|
107
109
|
const responseType = config.responseType;
|
@@ -373,6 +375,23 @@ export default function httpAdapter(config) {
|
|
373
375
|
|
374
376
|
const streams = [res];
|
375
377
|
|
378
|
+
const responseLength = +res.headers['content-length'];
|
379
|
+
|
380
|
+
if (onDownloadProgress) {
|
381
|
+
const transformStream = new AxiosTransformStream({
|
382
|
+
length: utils.toFiniteNumber(responseLength),
|
383
|
+
maxRate: utils.toFiniteNumber(maxDownloadRate)
|
384
|
+
});
|
385
|
+
|
386
|
+
onDownloadProgress && transformStream.on('progress', progress => {
|
387
|
+
onDownloadProgress(Object.assign(progress, {
|
388
|
+
download: true
|
389
|
+
}));
|
390
|
+
});
|
391
|
+
|
392
|
+
streams.push(transformStream);
|
393
|
+
}
|
394
|
+
|
376
395
|
// uncompress the response body transparently if required
|
377
396
|
let responseStream = res;
|
378
397
|
|
@@ -383,7 +402,7 @@ export default function httpAdapter(config) {
|
|
383
402
|
if (config.decompress !== false) {
|
384
403
|
// if no content, but headers still say that it is encoded,
|
385
404
|
// remove the header not confuse downstream operations
|
386
|
-
if (
|
405
|
+
if ((!responseLength || res.statusCode === 204) && res.headers['content-encoding']) {
|
387
406
|
delete res.headers['content-encoding'];
|
388
407
|
}
|
389
408
|
|
@@ -406,23 +425,6 @@ export default function httpAdapter(config) {
|
|
406
425
|
}
|
407
426
|
}
|
408
427
|
|
409
|
-
if (onDownloadProgress) {
|
410
|
-
const responseLength = +res.headers['content-length'];
|
411
|
-
|
412
|
-
const transformStream = new AxiosTransformStream({
|
413
|
-
length: utils.toFiniteNumber(responseLength),
|
414
|
-
maxRate: utils.toFiniteNumber(maxDownloadRate)
|
415
|
-
});
|
416
|
-
|
417
|
-
onDownloadProgress && transformStream.on('progress', progress => {
|
418
|
-
onDownloadProgress(Object.assign(progress, {
|
419
|
-
download: true
|
420
|
-
}));
|
421
|
-
});
|
422
|
-
|
423
|
-
streams.push(transformStream);
|
424
|
-
}
|
425
|
-
|
426
428
|
responseStream = streams.length > 1 ? stream.pipeline(streams, utils.noop) : streams[0];
|
427
429
|
|
428
430
|
const offListeners = stream.finished(responseStream, () => {
|
package/lib/adapters/xhr.js
CHANGED
@@ -43,7 +43,9 @@ function progressEventReducer(listener, isDownloadStream) {
|
|
43
43
|
};
|
44
44
|
}
|
45
45
|
|
46
|
-
|
46
|
+
const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
|
47
|
+
|
48
|
+
export default isXHRAdapterSupported && function (config) {
|
47
49
|
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
48
50
|
let requestData = config.data;
|
49
51
|
const requestHeaders = AxiosHeaders.from(config.headers).normalize();
|
package/lib/core/AxiosError.js
CHANGED
@@ -45,7 +45,7 @@ utils.inherits(AxiosError, Error, {
|
|
45
45
|
columnNumber: this.columnNumber,
|
46
46
|
stack: this.stack,
|
47
47
|
// Axios
|
48
|
-
config: this.config,
|
48
|
+
config: utils.toJSONObject(this.config),
|
49
49
|
code: this.code,
|
50
50
|
status: this.response && this.response.status ? this.response.status : null
|
51
51
|
};
|
@@ -5,6 +5,7 @@ import isCancel from '../cancel/isCancel.js';
|
|
5
5
|
import defaults from '../defaults/index.js';
|
6
6
|
import CanceledError from '../cancel/CanceledError.js';
|
7
7
|
import AxiosHeaders from '../core/AxiosHeaders.js';
|
8
|
+
import adapters from "../adapters/adapters.js";
|
8
9
|
|
9
10
|
/**
|
10
11
|
* Throws a `CanceledError` if cancellation has been requested.
|
@@ -45,7 +46,7 @@ export default function dispatchRequest(config) {
|
|
45
46
|
config.headers.setContentType('application/x-www-form-urlencoded', false);
|
46
47
|
}
|
47
48
|
|
48
|
-
const adapter = config.adapter || defaults.adapter;
|
49
|
+
const adapter = adapters.getAdapter(config.adapter || defaults.adapter);
|
49
50
|
|
50
51
|
return adapter(config).then(function onAdapterResolution(response) {
|
51
52
|
throwIfCancellationRequested(config);
|
package/lib/defaults/index.js
CHANGED
@@ -7,30 +7,11 @@ import toFormData from '../helpers/toFormData.js';
|
|
7
7
|
import toURLEncodedForm from '../helpers/toURLEncodedForm.js';
|
8
8
|
import platform from '../platform/index.js';
|
9
9
|
import formDataToJSON from '../helpers/formDataToJSON.js';
|
10
|
-
import adapters from '../adapters/index.js';
|
11
10
|
|
12
11
|
const DEFAULT_CONTENT_TYPE = {
|
13
12
|
'Content-Type': undefined
|
14
13
|
};
|
15
14
|
|
16
|
-
/**
|
17
|
-
* If the browser has an XMLHttpRequest object, use the XHR adapter, otherwise use the HTTP
|
18
|
-
* adapter
|
19
|
-
*
|
20
|
-
* @returns {Function}
|
21
|
-
*/
|
22
|
-
function getDefaultAdapter() {
|
23
|
-
let adapter;
|
24
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
25
|
-
// For browsers use XHR adapter
|
26
|
-
adapter = adapters.getAdapter('xhr');
|
27
|
-
} else if (typeof process !== 'undefined' && utils.kindOf(process) === 'process') {
|
28
|
-
// For node use HTTP adapter
|
29
|
-
adapter = adapters.getAdapter('http');
|
30
|
-
}
|
31
|
-
return adapter;
|
32
|
-
}
|
33
|
-
|
34
15
|
/**
|
35
16
|
* It takes a string, tries to parse it, and if it fails, it returns the stringified version
|
36
17
|
* of the input
|
@@ -60,7 +41,7 @@ const defaults = {
|
|
60
41
|
|
61
42
|
transitional: transitionalDefaults,
|
62
43
|
|
63
|
-
adapter:
|
44
|
+
adapter: ['xhr', 'http'],
|
64
45
|
|
65
46
|
transformRequest: [function transformRequest(data, headers) {
|
66
47
|
const contentType = headers.getContentType() || '';
|
package/lib/env/data.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = "1.2.0
|
1
|
+
export const VERSION = "1.2.0";
|
package/lib/utils.js
CHANGED
@@ -592,6 +592,37 @@ const toFiniteNumber = (value, defaultValue) => {
|
|
592
592
|
return Number.isFinite(value) ? value : defaultValue;
|
593
593
|
}
|
594
594
|
|
595
|
+
const toJSONObject = (obj) => {
|
596
|
+
const stack = new Array(10);
|
597
|
+
|
598
|
+
const visit = (source, i) => {
|
599
|
+
|
600
|
+
if (isObject(source)) {
|
601
|
+
if (stack.indexOf(source) >= 0) {
|
602
|
+
return;
|
603
|
+
}
|
604
|
+
|
605
|
+
if(!('toJSON' in source)) {
|
606
|
+
stack[i] = source;
|
607
|
+
const target = isArray(source) ? [] : {};
|
608
|
+
|
609
|
+
forEach(source, (value, key) => {
|
610
|
+
const reducedValue = visit(value, i + 1);
|
611
|
+
!isUndefined(reducedValue) && (target[key] = reducedValue);
|
612
|
+
});
|
613
|
+
|
614
|
+
stack[i] = undefined;
|
615
|
+
|
616
|
+
return target;
|
617
|
+
}
|
618
|
+
}
|
619
|
+
|
620
|
+
return source;
|
621
|
+
}
|
622
|
+
|
623
|
+
return visit(obj, 0);
|
624
|
+
}
|
625
|
+
|
595
626
|
export default {
|
596
627
|
isArray,
|
597
628
|
isArrayBuffer,
|
@@ -637,5 +668,6 @@ export default {
|
|
637
668
|
toFiniteNumber,
|
638
669
|
findKey,
|
639
670
|
global: _global,
|
640
|
-
isContextDefined
|
671
|
+
isContextDefined,
|
672
|
+
toJSONObject
|
641
673
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "axios",
|
3
|
-
"version": "1.2.0
|
3
|
+
"version": "1.2.0",
|
4
4
|
"description": "Promise based HTTP client for the browser and node.js",
|
5
5
|
"main": "index.js",
|
6
6
|
"exports": {
|
@@ -104,7 +104,7 @@
|
|
104
104
|
"url-search-params": "^0.10.0"
|
105
105
|
},
|
106
106
|
"browser": {
|
107
|
-
"./lib/adapters/http.js": "./lib/
|
107
|
+
"./lib/adapters/http.js": "./lib/helpers/null.js",
|
108
108
|
"./lib/platform/node/index.js": "./lib/platform/browser/index.js"
|
109
109
|
},
|
110
110
|
"jsdelivr": "dist/axios.min.js",
|
package/lib/adapters/index.js
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
import utils from '../utils.js';
|
2
|
-
import httpAdapter from './http.js';
|
3
|
-
import xhrAdapter from './xhr.js';
|
4
|
-
|
5
|
-
const adapters = {
|
6
|
-
http: httpAdapter,
|
7
|
-
xhr: xhrAdapter
|
8
|
-
}
|
9
|
-
|
10
|
-
export default {
|
11
|
-
getAdapter: (nameOrAdapter) => {
|
12
|
-
if(utils.isString(nameOrAdapter)){
|
13
|
-
const adapter = adapters[nameOrAdapter];
|
14
|
-
|
15
|
-
if (!nameOrAdapter) {
|
16
|
-
throw Error(
|
17
|
-
utils.hasOwnProp(nameOrAdapter) ?
|
18
|
-
`Adapter '${nameOrAdapter}' is not available in the build` :
|
19
|
-
`Can not resolve adapter '${nameOrAdapter}'`
|
20
|
-
);
|
21
|
-
}
|
22
|
-
|
23
|
-
return adapter
|
24
|
-
}
|
25
|
-
|
26
|
-
if (!utils.isFunction(nameOrAdapter)) {
|
27
|
-
throw new TypeError('adapter is not a function');
|
28
|
-
}
|
29
|
-
|
30
|
-
return nameOrAdapter;
|
31
|
-
},
|
32
|
-
adapters
|
33
|
-
}
|