axios 0.14.0 → 0.15.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 axios might be problematic. Click here for more details.
- package/CHANGELOG.md +31 -6
- package/README.md +582 -0
- package/dist/axios.js +353 -208
- package/dist/axios.map +1 -1
- package/dist/axios.min.js +2 -2
- package/dist/axios.min.map +1 -1
- package/{axios.d.ts → index.d.ts} +32 -0
- package/lib/adapters/http.js +34 -3
- package/lib/adapters/xhr.js +17 -2
- package/lib/axios.js +9 -3
- package/lib/cancel/Cancel.js +19 -0
- package/lib/cancel/CancelToken.js +57 -0
- package/lib/cancel/isCancel.js +5 -0
- package/lib/core/Axios.js +3 -3
- package/lib/core/dispatchRequest.js +35 -31
- package/lib/defaults.js +31 -10
- package/lib/utils.js +1 -1
- package/package.json +22 -21
package/dist/axios.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* axios v0.
|
1
|
+
/* axios v0.15.3 | (c) 2016 by Matt Zabriskie */
|
2
2
|
(function webpackUniversalModuleDefinition(root, factory) {
|
3
3
|
if(typeof exports === 'object' && typeof module === 'object')
|
4
4
|
module.exports = factory();
|
@@ -66,6 +66,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
66
66
|
var utils = __webpack_require__(2);
|
67
67
|
var bind = __webpack_require__(3);
|
68
68
|
var Axios = __webpack_require__(4);
|
69
|
+
var defaults = __webpack_require__(5);
|
69
70
|
|
70
71
|
/**
|
71
72
|
* Create an instance of Axios
|
@@ -87,21 +88,26 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
87
88
|
}
|
88
89
|
|
89
90
|
// Create the default instance to be exported
|
90
|
-
var axios = createInstance();
|
91
|
+
var axios = createInstance(defaults);
|
91
92
|
|
92
93
|
// Expose Axios class to allow class inheritance
|
93
94
|
axios.Axios = Axios;
|
94
95
|
|
95
96
|
// Factory for creating new instances
|
96
|
-
axios.create = function create(
|
97
|
-
return createInstance(
|
97
|
+
axios.create = function create(instanceConfig) {
|
98
|
+
return createInstance(utils.merge(defaults, instanceConfig));
|
98
99
|
};
|
99
100
|
|
101
|
+
// Expose Cancel & CancelToken
|
102
|
+
axios.Cancel = __webpack_require__(22);
|
103
|
+
axios.CancelToken = __webpack_require__(23);
|
104
|
+
axios.isCancel = __webpack_require__(19);
|
105
|
+
|
100
106
|
// Expose all/spread
|
101
107
|
axios.all = function all(promises) {
|
102
108
|
return Promise.all(promises);
|
103
109
|
};
|
104
|
-
axios.spread = __webpack_require__(
|
110
|
+
axios.spread = __webpack_require__(24);
|
105
111
|
|
106
112
|
module.exports = axios;
|
107
113
|
|
@@ -332,7 +338,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
332
338
|
} else {
|
333
339
|
// Iterate over object keys
|
334
340
|
for (var key in obj) {
|
335
|
-
if (
|
341
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
336
342
|
fn.call(null, obj[key], key, obj);
|
337
343
|
}
|
338
344
|
}
|
@@ -439,18 +445,18 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
439
445
|
|
440
446
|
var defaults = __webpack_require__(5);
|
441
447
|
var utils = __webpack_require__(2);
|
442
|
-
var InterceptorManager = __webpack_require__(
|
443
|
-
var dispatchRequest = __webpack_require__(
|
444
|
-
var isAbsoluteURL = __webpack_require__(
|
445
|
-
var combineURLs = __webpack_require__(
|
448
|
+
var InterceptorManager = __webpack_require__(16);
|
449
|
+
var dispatchRequest = __webpack_require__(17);
|
450
|
+
var isAbsoluteURL = __webpack_require__(20);
|
451
|
+
var combineURLs = __webpack_require__(21);
|
446
452
|
|
447
453
|
/**
|
448
454
|
* Create a new instance of Axios
|
449
455
|
*
|
450
|
-
* @param {Object}
|
456
|
+
* @param {Object} instanceConfig The default config for the instance
|
451
457
|
*/
|
452
|
-
function Axios(
|
453
|
-
this.defaults =
|
458
|
+
function Axios(instanceConfig) {
|
459
|
+
this.defaults = instanceConfig;
|
454
460
|
this.interceptors = {
|
455
461
|
request: new InterceptorManager(),
|
456
462
|
response: new InterceptorManager()
|
@@ -542,7 +548,21 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
542
548
|
}
|
543
549
|
}
|
544
550
|
|
545
|
-
|
551
|
+
function getDefaultAdapter() {
|
552
|
+
var adapter;
|
553
|
+
if (typeof XMLHttpRequest !== 'undefined') {
|
554
|
+
// For browsers use XHR adapter
|
555
|
+
adapter = __webpack_require__(7);
|
556
|
+
} else if (typeof process !== 'undefined') {
|
557
|
+
// For node use HTTP adapter
|
558
|
+
adapter = __webpack_require__(7);
|
559
|
+
}
|
560
|
+
return adapter;
|
561
|
+
}
|
562
|
+
|
563
|
+
var defaults = {
|
564
|
+
adapter: getDefaultAdapter(),
|
565
|
+
|
546
566
|
transformRequest: [function transformRequest(data, headers) {
|
547
567
|
normalizeHeaderName(headers, 'Content-Type');
|
548
568
|
if (utils.isFormData(data) ||
|
@@ -578,15 +598,6 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
578
598
|
return data;
|
579
599
|
}],
|
580
600
|
|
581
|
-
headers: {
|
582
|
-
common: {
|
583
|
-
'Accept': 'application/json, text/plain, */*'
|
584
|
-
},
|
585
|
-
patch: utils.merge(DEFAULT_CONTENT_TYPE),
|
586
|
-
post: utils.merge(DEFAULT_CONTENT_TYPE),
|
587
|
-
put: utils.merge(DEFAULT_CONTENT_TYPE)
|
588
|
-
},
|
589
|
-
|
590
601
|
timeout: 0,
|
591
602
|
|
592
603
|
xsrfCookieName: 'XSRF-TOKEN',
|
@@ -598,6 +609,22 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
598
609
|
return status >= 200 && status < 300;
|
599
610
|
}
|
600
611
|
};
|
612
|
+
|
613
|
+
defaults.headers = {
|
614
|
+
common: {
|
615
|
+
'Accept': 'application/json, text/plain, */*'
|
616
|
+
}
|
617
|
+
};
|
618
|
+
|
619
|
+
utils.forEach(['delete', 'get', 'head'], function forEachMehtodNoData(method) {
|
620
|
+
defaults.headers[method] = {};
|
621
|
+
});
|
622
|
+
|
623
|
+
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
624
|
+
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
625
|
+
});
|
626
|
+
|
627
|
+
module.exports = defaults;
|
601
628
|
|
602
629
|
|
603
630
|
/***/ },
|
@@ -625,177 +652,12 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
625
652
|
'use strict';
|
626
653
|
|
627
654
|
var utils = __webpack_require__(2);
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
* Add a new interceptor to the stack
|
635
|
-
*
|
636
|
-
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
637
|
-
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
638
|
-
*
|
639
|
-
* @return {Number} An ID used to remove interceptor later
|
640
|
-
*/
|
641
|
-
InterceptorManager.prototype.use = function use(fulfilled, rejected) {
|
642
|
-
this.handlers.push({
|
643
|
-
fulfilled: fulfilled,
|
644
|
-
rejected: rejected
|
645
|
-
});
|
646
|
-
return this.handlers.length - 1;
|
647
|
-
};
|
648
|
-
|
649
|
-
/**
|
650
|
-
* Remove an interceptor from the stack
|
651
|
-
*
|
652
|
-
* @param {Number} id The ID that was returned by `use`
|
653
|
-
*/
|
654
|
-
InterceptorManager.prototype.eject = function eject(id) {
|
655
|
-
if (this.handlers[id]) {
|
656
|
-
this.handlers[id] = null;
|
657
|
-
}
|
658
|
-
};
|
659
|
-
|
660
|
-
/**
|
661
|
-
* Iterate over all the registered interceptors
|
662
|
-
*
|
663
|
-
* This method is particularly useful for skipping over any
|
664
|
-
* interceptors that may have become `null` calling `eject`.
|
665
|
-
*
|
666
|
-
* @param {Function} fn The function to call for each interceptor
|
667
|
-
*/
|
668
|
-
InterceptorManager.prototype.forEach = function forEach(fn) {
|
669
|
-
utils.forEach(this.handlers, function forEachHandler(h) {
|
670
|
-
if (h !== null) {
|
671
|
-
fn(h);
|
672
|
-
}
|
673
|
-
});
|
674
|
-
};
|
675
|
-
|
676
|
-
module.exports = InterceptorManager;
|
677
|
-
|
678
|
-
|
679
|
-
/***/ },
|
680
|
-
/* 8 */
|
681
|
-
/***/ function(module, exports, __webpack_require__) {
|
682
|
-
|
683
|
-
'use strict';
|
684
|
-
|
685
|
-
var utils = __webpack_require__(2);
|
686
|
-
var transformData = __webpack_require__(9);
|
687
|
-
|
688
|
-
/**
|
689
|
-
* Dispatch a request to the server using whichever adapter
|
690
|
-
* is supported by the current environment.
|
691
|
-
*
|
692
|
-
* @param {object} config The config that is to be used for the request
|
693
|
-
* @returns {Promise} The Promise to be fulfilled
|
694
|
-
*/
|
695
|
-
module.exports = function dispatchRequest(config) {
|
696
|
-
// Ensure headers exist
|
697
|
-
config.headers = config.headers || {};
|
698
|
-
|
699
|
-
// Transform request data
|
700
|
-
config.data = transformData(
|
701
|
-
config.data,
|
702
|
-
config.headers,
|
703
|
-
config.transformRequest
|
704
|
-
);
|
705
|
-
|
706
|
-
// Flatten headers
|
707
|
-
config.headers = utils.merge(
|
708
|
-
config.headers.common || {},
|
709
|
-
config.headers[config.method] || {},
|
710
|
-
config.headers || {}
|
711
|
-
);
|
712
|
-
|
713
|
-
utils.forEach(
|
714
|
-
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
715
|
-
function cleanHeaderConfig(method) {
|
716
|
-
delete config.headers[method];
|
717
|
-
}
|
718
|
-
);
|
719
|
-
|
720
|
-
var adapter;
|
721
|
-
|
722
|
-
if (typeof config.adapter === 'function') {
|
723
|
-
// For custom adapter support
|
724
|
-
adapter = config.adapter;
|
725
|
-
} else if (typeof XMLHttpRequest !== 'undefined') {
|
726
|
-
// For browsers use XHR adapter
|
727
|
-
adapter = __webpack_require__(10);
|
728
|
-
} else if (typeof process !== 'undefined') {
|
729
|
-
// For node use HTTP adapter
|
730
|
-
adapter = __webpack_require__(10);
|
731
|
-
}
|
732
|
-
|
733
|
-
return Promise.resolve(config)
|
734
|
-
// Wrap synchronous adapter errors and pass configuration
|
735
|
-
.then(adapter)
|
736
|
-
.then(function onFulfilled(response) {
|
737
|
-
// Transform response data
|
738
|
-
response.data = transformData(
|
739
|
-
response.data,
|
740
|
-
response.headers,
|
741
|
-
config.transformResponse
|
742
|
-
);
|
743
|
-
|
744
|
-
return response;
|
745
|
-
}, function onRejected(error) {
|
746
|
-
// Transform response data
|
747
|
-
if (error && error.response) {
|
748
|
-
error.response.data = transformData(
|
749
|
-
error.response.data,
|
750
|
-
error.response.headers,
|
751
|
-
config.transformResponse
|
752
|
-
);
|
753
|
-
}
|
754
|
-
|
755
|
-
return Promise.reject(error);
|
756
|
-
});
|
757
|
-
};
|
758
|
-
|
759
|
-
|
760
|
-
/***/ },
|
761
|
-
/* 9 */
|
762
|
-
/***/ function(module, exports, __webpack_require__) {
|
763
|
-
|
764
|
-
'use strict';
|
765
|
-
|
766
|
-
var utils = __webpack_require__(2);
|
767
|
-
|
768
|
-
/**
|
769
|
-
* Transform the data for a request or a response
|
770
|
-
*
|
771
|
-
* @param {Object|String} data The data to be transformed
|
772
|
-
* @param {Array} headers The headers for the request or response
|
773
|
-
* @param {Array|Function} fns A single function or Array of functions
|
774
|
-
* @returns {*} The resulting transformed data
|
775
|
-
*/
|
776
|
-
module.exports = function transformData(data, headers, fns) {
|
777
|
-
/*eslint no-param-reassign:0*/
|
778
|
-
utils.forEach(fns, function transform(fn) {
|
779
|
-
data = fn(data, headers);
|
780
|
-
});
|
781
|
-
|
782
|
-
return data;
|
783
|
-
};
|
784
|
-
|
785
|
-
|
786
|
-
/***/ },
|
787
|
-
/* 10 */
|
788
|
-
/***/ function(module, exports, __webpack_require__) {
|
789
|
-
|
790
|
-
'use strict';
|
791
|
-
|
792
|
-
var utils = __webpack_require__(2);
|
793
|
-
var settle = __webpack_require__(11);
|
794
|
-
var buildURL = __webpack_require__(14);
|
795
|
-
var parseHeaders = __webpack_require__(15);
|
796
|
-
var isURLSameOrigin = __webpack_require__(16);
|
797
|
-
var createError = __webpack_require__(12);
|
798
|
-
var btoa = (typeof window !== 'undefined' && window.btoa) || __webpack_require__(17);
|
655
|
+
var settle = __webpack_require__(8);
|
656
|
+
var buildURL = __webpack_require__(11);
|
657
|
+
var parseHeaders = __webpack_require__(12);
|
658
|
+
var isURLSameOrigin = __webpack_require__(13);
|
659
|
+
var createError = __webpack_require__(9);
|
660
|
+
var btoa = (typeof window !== 'undefined' && window.btoa && window.btoa.bind(window)) || __webpack_require__(14);
|
799
661
|
|
800
662
|
module.exports = function xhrAdapter(config) {
|
801
663
|
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
@@ -844,7 +706,9 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
844
706
|
|
845
707
|
// The request errored out and we didn't get a response, this will be
|
846
708
|
// handled by onerror instead
|
847
|
-
|
709
|
+
// With one exception: request that using file: protocol, most browsers
|
710
|
+
// will return status as 0 even though it's a successful request
|
711
|
+
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
848
712
|
return;
|
849
713
|
}
|
850
714
|
|
@@ -889,7 +753,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
889
753
|
// This is only done if running in a standard browser environment.
|
890
754
|
// Specifically not if we're in a web worker, or react-native.
|
891
755
|
if (utils.isStandardBrowserEnv()) {
|
892
|
-
var cookies = __webpack_require__(
|
756
|
+
var cookies = __webpack_require__(15);
|
893
757
|
|
894
758
|
// Add xsrf header
|
895
759
|
var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ?
|
@@ -940,6 +804,19 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
940
804
|
request.upload.addEventListener('progress', config.onUploadProgress);
|
941
805
|
}
|
942
806
|
|
807
|
+
if (config.cancelToken) {
|
808
|
+
// Handle cancellation
|
809
|
+
config.cancelToken.promise.then(function onCanceled(cancel) {
|
810
|
+
if (!request) {
|
811
|
+
return;
|
812
|
+
}
|
813
|
+
|
814
|
+
request.abort();
|
815
|
+
reject(cancel);
|
816
|
+
// Clean up request
|
817
|
+
request = null;
|
818
|
+
});
|
819
|
+
}
|
943
820
|
|
944
821
|
if (requestData === undefined) {
|
945
822
|
requestData = null;
|
@@ -952,12 +829,12 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
952
829
|
|
953
830
|
|
954
831
|
/***/ },
|
955
|
-
/*
|
832
|
+
/* 8 */
|
956
833
|
/***/ function(module, exports, __webpack_require__) {
|
957
834
|
|
958
835
|
'use strict';
|
959
836
|
|
960
|
-
var createError = __webpack_require__(
|
837
|
+
var createError = __webpack_require__(9);
|
961
838
|
|
962
839
|
/**
|
963
840
|
* Resolve or reject a Promise based on response status.
|
@@ -983,12 +860,12 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
983
860
|
|
984
861
|
|
985
862
|
/***/ },
|
986
|
-
/*
|
863
|
+
/* 9 */
|
987
864
|
/***/ function(module, exports, __webpack_require__) {
|
988
865
|
|
989
866
|
'use strict';
|
990
867
|
|
991
|
-
var enhanceError = __webpack_require__(
|
868
|
+
var enhanceError = __webpack_require__(10);
|
992
869
|
|
993
870
|
/**
|
994
871
|
* Create an Error with the specified message, config, error code, and response.
|
@@ -1006,7 +883,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
1006
883
|
|
1007
884
|
|
1008
885
|
/***/ },
|
1009
|
-
/*
|
886
|
+
/* 10 */
|
1010
887
|
/***/ function(module, exports) {
|
1011
888
|
|
1012
889
|
'use strict';
|
@@ -1031,7 +908,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
1031
908
|
|
1032
909
|
|
1033
910
|
/***/ },
|
1034
|
-
/*
|
911
|
+
/* 11 */
|
1035
912
|
/***/ function(module, exports, __webpack_require__) {
|
1036
913
|
|
1037
914
|
'use strict';
|
@@ -1105,7 +982,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
1105
982
|
|
1106
983
|
|
1107
984
|
/***/ },
|
1108
|
-
/*
|
985
|
+
/* 12 */
|
1109
986
|
/***/ function(module, exports, __webpack_require__) {
|
1110
987
|
|
1111
988
|
'use strict';
|
@@ -1148,7 +1025,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
1148
1025
|
|
1149
1026
|
|
1150
1027
|
/***/ },
|
1151
|
-
/*
|
1028
|
+
/* 13 */
|
1152
1029
|
/***/ function(module, exports, __webpack_require__) {
|
1153
1030
|
|
1154
1031
|
'use strict';
|
@@ -1222,7 +1099,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
1222
1099
|
|
1223
1100
|
|
1224
1101
|
/***/ },
|
1225
|
-
/*
|
1102
|
+
/* 14 */
|
1226
1103
|
/***/ function(module, exports) {
|
1227
1104
|
|
1228
1105
|
'use strict';
|
@@ -1264,7 +1141,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
1264
1141
|
|
1265
1142
|
|
1266
1143
|
/***/ },
|
1267
|
-
/*
|
1144
|
+
/* 15 */
|
1268
1145
|
/***/ function(module, exports, __webpack_require__) {
|
1269
1146
|
|
1270
1147
|
'use strict';
|
@@ -1322,12 +1199,192 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
1322
1199
|
);
|
1323
1200
|
|
1324
1201
|
|
1202
|
+
/***/ },
|
1203
|
+
/* 16 */
|
1204
|
+
/***/ function(module, exports, __webpack_require__) {
|
1205
|
+
|
1206
|
+
'use strict';
|
1207
|
+
|
1208
|
+
var utils = __webpack_require__(2);
|
1209
|
+
|
1210
|
+
function InterceptorManager() {
|
1211
|
+
this.handlers = [];
|
1212
|
+
}
|
1213
|
+
|
1214
|
+
/**
|
1215
|
+
* Add a new interceptor to the stack
|
1216
|
+
*
|
1217
|
+
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
1218
|
+
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
1219
|
+
*
|
1220
|
+
* @return {Number} An ID used to remove interceptor later
|
1221
|
+
*/
|
1222
|
+
InterceptorManager.prototype.use = function use(fulfilled, rejected) {
|
1223
|
+
this.handlers.push({
|
1224
|
+
fulfilled: fulfilled,
|
1225
|
+
rejected: rejected
|
1226
|
+
});
|
1227
|
+
return this.handlers.length - 1;
|
1228
|
+
};
|
1229
|
+
|
1230
|
+
/**
|
1231
|
+
* Remove an interceptor from the stack
|
1232
|
+
*
|
1233
|
+
* @param {Number} id The ID that was returned by `use`
|
1234
|
+
*/
|
1235
|
+
InterceptorManager.prototype.eject = function eject(id) {
|
1236
|
+
if (this.handlers[id]) {
|
1237
|
+
this.handlers[id] = null;
|
1238
|
+
}
|
1239
|
+
};
|
1240
|
+
|
1241
|
+
/**
|
1242
|
+
* Iterate over all the registered interceptors
|
1243
|
+
*
|
1244
|
+
* This method is particularly useful for skipping over any
|
1245
|
+
* interceptors that may have become `null` calling `eject`.
|
1246
|
+
*
|
1247
|
+
* @param {Function} fn The function to call for each interceptor
|
1248
|
+
*/
|
1249
|
+
InterceptorManager.prototype.forEach = function forEach(fn) {
|
1250
|
+
utils.forEach(this.handlers, function forEachHandler(h) {
|
1251
|
+
if (h !== null) {
|
1252
|
+
fn(h);
|
1253
|
+
}
|
1254
|
+
});
|
1255
|
+
};
|
1256
|
+
|
1257
|
+
module.exports = InterceptorManager;
|
1258
|
+
|
1259
|
+
|
1260
|
+
/***/ },
|
1261
|
+
/* 17 */
|
1262
|
+
/***/ function(module, exports, __webpack_require__) {
|
1263
|
+
|
1264
|
+
'use strict';
|
1265
|
+
|
1266
|
+
var utils = __webpack_require__(2);
|
1267
|
+
var transformData = __webpack_require__(18);
|
1268
|
+
var isCancel = __webpack_require__(19);
|
1269
|
+
var defaults = __webpack_require__(5);
|
1270
|
+
|
1271
|
+
/**
|
1272
|
+
* Throws a `Cancel` if cancellation has been requested.
|
1273
|
+
*/
|
1274
|
+
function throwIfCancellationRequested(config) {
|
1275
|
+
if (config.cancelToken) {
|
1276
|
+
config.cancelToken.throwIfRequested();
|
1277
|
+
}
|
1278
|
+
}
|
1279
|
+
|
1280
|
+
/**
|
1281
|
+
* Dispatch a request to the server using the configured adapter.
|
1282
|
+
*
|
1283
|
+
* @param {object} config The config that is to be used for the request
|
1284
|
+
* @returns {Promise} The Promise to be fulfilled
|
1285
|
+
*/
|
1286
|
+
module.exports = function dispatchRequest(config) {
|
1287
|
+
throwIfCancellationRequested(config);
|
1288
|
+
|
1289
|
+
// Ensure headers exist
|
1290
|
+
config.headers = config.headers || {};
|
1291
|
+
|
1292
|
+
// Transform request data
|
1293
|
+
config.data = transformData(
|
1294
|
+
config.data,
|
1295
|
+
config.headers,
|
1296
|
+
config.transformRequest
|
1297
|
+
);
|
1298
|
+
|
1299
|
+
// Flatten headers
|
1300
|
+
config.headers = utils.merge(
|
1301
|
+
config.headers.common || {},
|
1302
|
+
config.headers[config.method] || {},
|
1303
|
+
config.headers || {}
|
1304
|
+
);
|
1305
|
+
|
1306
|
+
utils.forEach(
|
1307
|
+
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
1308
|
+
function cleanHeaderConfig(method) {
|
1309
|
+
delete config.headers[method];
|
1310
|
+
}
|
1311
|
+
);
|
1312
|
+
|
1313
|
+
var adapter = config.adapter || defaults.adapter;
|
1314
|
+
|
1315
|
+
return adapter(config).then(function onAdapterResolution(response) {
|
1316
|
+
throwIfCancellationRequested(config);
|
1317
|
+
|
1318
|
+
// Transform response data
|
1319
|
+
response.data = transformData(
|
1320
|
+
response.data,
|
1321
|
+
response.headers,
|
1322
|
+
config.transformResponse
|
1323
|
+
);
|
1324
|
+
|
1325
|
+
return response;
|
1326
|
+
}, function onAdapterRejection(reason) {
|
1327
|
+
if (!isCancel(reason)) {
|
1328
|
+
throwIfCancellationRequested(config);
|
1329
|
+
|
1330
|
+
// Transform response data
|
1331
|
+
if (reason && reason.response) {
|
1332
|
+
reason.response.data = transformData(
|
1333
|
+
reason.response.data,
|
1334
|
+
reason.response.headers,
|
1335
|
+
config.transformResponse
|
1336
|
+
);
|
1337
|
+
}
|
1338
|
+
}
|
1339
|
+
|
1340
|
+
return Promise.reject(reason);
|
1341
|
+
});
|
1342
|
+
};
|
1343
|
+
|
1344
|
+
|
1345
|
+
/***/ },
|
1346
|
+
/* 18 */
|
1347
|
+
/***/ function(module, exports, __webpack_require__) {
|
1348
|
+
|
1349
|
+
'use strict';
|
1350
|
+
|
1351
|
+
var utils = __webpack_require__(2);
|
1352
|
+
|
1353
|
+
/**
|
1354
|
+
* Transform the data for a request or a response
|
1355
|
+
*
|
1356
|
+
* @param {Object|String} data The data to be transformed
|
1357
|
+
* @param {Array} headers The headers for the request or response
|
1358
|
+
* @param {Array|Function} fns A single function or Array of functions
|
1359
|
+
* @returns {*} The resulting transformed data
|
1360
|
+
*/
|
1361
|
+
module.exports = function transformData(data, headers, fns) {
|
1362
|
+
/*eslint no-param-reassign:0*/
|
1363
|
+
utils.forEach(fns, function transform(fn) {
|
1364
|
+
data = fn(data, headers);
|
1365
|
+
});
|
1366
|
+
|
1367
|
+
return data;
|
1368
|
+
};
|
1369
|
+
|
1370
|
+
|
1325
1371
|
/***/ },
|
1326
1372
|
/* 19 */
|
1327
1373
|
/***/ function(module, exports) {
|
1328
1374
|
|
1329
1375
|
'use strict';
|
1330
1376
|
|
1377
|
+
module.exports = function isCancel(value) {
|
1378
|
+
return !!(value && value.__CANCEL__);
|
1379
|
+
};
|
1380
|
+
|
1381
|
+
|
1382
|
+
/***/ },
|
1383
|
+
/* 20 */
|
1384
|
+
/***/ function(module, exports) {
|
1385
|
+
|
1386
|
+
'use strict';
|
1387
|
+
|
1331
1388
|
/**
|
1332
1389
|
* Determines whether the specified URL is absolute
|
1333
1390
|
*
|
@@ -1343,7 +1400,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
1343
1400
|
|
1344
1401
|
|
1345
1402
|
/***/ },
|
1346
|
-
/*
|
1403
|
+
/* 21 */
|
1347
1404
|
/***/ function(module, exports) {
|
1348
1405
|
|
1349
1406
|
'use strict';
|
@@ -1361,7 +1418,95 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
1361
1418
|
|
1362
1419
|
|
1363
1420
|
/***/ },
|
1364
|
-
/*
|
1421
|
+
/* 22 */
|
1422
|
+
/***/ function(module, exports) {
|
1423
|
+
|
1424
|
+
'use strict';
|
1425
|
+
|
1426
|
+
/**
|
1427
|
+
* A `Cancel` is an object that is thrown when an operation is canceled.
|
1428
|
+
*
|
1429
|
+
* @class
|
1430
|
+
* @param {string=} message The message.
|
1431
|
+
*/
|
1432
|
+
function Cancel(message) {
|
1433
|
+
this.message = message;
|
1434
|
+
}
|
1435
|
+
|
1436
|
+
Cancel.prototype.toString = function toString() {
|
1437
|
+
return 'Cancel' + (this.message ? ': ' + this.message : '');
|
1438
|
+
};
|
1439
|
+
|
1440
|
+
Cancel.prototype.__CANCEL__ = true;
|
1441
|
+
|
1442
|
+
module.exports = Cancel;
|
1443
|
+
|
1444
|
+
|
1445
|
+
/***/ },
|
1446
|
+
/* 23 */
|
1447
|
+
/***/ function(module, exports, __webpack_require__) {
|
1448
|
+
|
1449
|
+
'use strict';
|
1450
|
+
|
1451
|
+
var Cancel = __webpack_require__(22);
|
1452
|
+
|
1453
|
+
/**
|
1454
|
+
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
1455
|
+
*
|
1456
|
+
* @class
|
1457
|
+
* @param {Function} executor The executor function.
|
1458
|
+
*/
|
1459
|
+
function CancelToken(executor) {
|
1460
|
+
if (typeof executor !== 'function') {
|
1461
|
+
throw new TypeError('executor must be a function.');
|
1462
|
+
}
|
1463
|
+
|
1464
|
+
var resolvePromise;
|
1465
|
+
this.promise = new Promise(function promiseExecutor(resolve) {
|
1466
|
+
resolvePromise = resolve;
|
1467
|
+
});
|
1468
|
+
|
1469
|
+
var token = this;
|
1470
|
+
executor(function cancel(message) {
|
1471
|
+
if (token.reason) {
|
1472
|
+
// Cancellation has already been requested
|
1473
|
+
return;
|
1474
|
+
}
|
1475
|
+
|
1476
|
+
token.reason = new Cancel(message);
|
1477
|
+
resolvePromise(token.reason);
|
1478
|
+
});
|
1479
|
+
}
|
1480
|
+
|
1481
|
+
/**
|
1482
|
+
* Throws a `Cancel` if cancellation has been requested.
|
1483
|
+
*/
|
1484
|
+
CancelToken.prototype.throwIfRequested = function throwIfRequested() {
|
1485
|
+
if (this.reason) {
|
1486
|
+
throw this.reason;
|
1487
|
+
}
|
1488
|
+
};
|
1489
|
+
|
1490
|
+
/**
|
1491
|
+
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
1492
|
+
* cancels the `CancelToken`.
|
1493
|
+
*/
|
1494
|
+
CancelToken.source = function source() {
|
1495
|
+
var cancel;
|
1496
|
+
var token = new CancelToken(function executor(c) {
|
1497
|
+
cancel = c;
|
1498
|
+
});
|
1499
|
+
return {
|
1500
|
+
token: token,
|
1501
|
+
cancel: cancel
|
1502
|
+
};
|
1503
|
+
};
|
1504
|
+
|
1505
|
+
module.exports = CancelToken;
|
1506
|
+
|
1507
|
+
|
1508
|
+
/***/ },
|
1509
|
+
/* 24 */
|
1365
1510
|
/***/ function(module, exports) {
|
1366
1511
|
|
1367
1512
|
'use strict';
|