axios.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533
  1. /* axios v0.18.1 | (c) 2019 by Matt Zabriskie */
  2. (function webpackUniversalModuleDefinition(root, factory) {
  3. if(typeof exports === 'object' && typeof module === 'object')
  4. module.exports = factory();
  5. else if(typeof define === 'function' && define.amd)
  6. define([], factory);
  7. else if(typeof exports === 'object')
  8. exports["axios"] = factory();
  9. else
  10. root["axios"] = factory();
  11. })(this, function() {
  12. return /******/ (function(modules) { // webpackBootstrap
  13. /******/ // The module cache
  14. /******/ var installedModules = {};
  15. /******/
  16. /******/ // The require function
  17. /******/ function __webpack_require__(moduleId) {
  18. /******/
  19. /******/ // Check if module is in cache
  20. /******/ if(installedModules[moduleId])
  21. /******/ return installedModules[moduleId].exports;
  22. /******/
  23. /******/ // Create a new module (and put it into the cache)
  24. /******/ var module = installedModules[moduleId] = {
  25. /******/ exports: {},
  26. /******/ id: moduleId,
  27. /******/ loaded: false
  28. /******/ };
  29. /******/
  30. /******/ // Execute the module function
  31. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  32. /******/
  33. /******/ // Flag the module as loaded
  34. /******/ module.loaded = true;
  35. /******/
  36. /******/ // Return the exports of the module
  37. /******/ return module.exports;
  38. /******/ }
  39. /******/
  40. /******/
  41. /******/ // expose the modules object (__webpack_modules__)
  42. /******/ __webpack_require__.m = modules;
  43. /******/
  44. /******/ // expose the module cache
  45. /******/ __webpack_require__.c = installedModules;
  46. /******/
  47. /******/ // __webpack_public_path__
  48. /******/ __webpack_require__.p = "";
  49. /******/
  50. /******/ // Load entry module and return exports
  51. /******/ return __webpack_require__(0);
  52. /******/ })
  53. /************************************************************************/
  54. /******/ ([
  55. /* 0 */
  56. /***/ (function(module, exports, __webpack_require__) {
  57. module.exports = __webpack_require__(1);
  58. /***/ }),
  59. /* 1 */
  60. /***/ (function(module, exports, __webpack_require__) {
  61. 'use strict';
  62. var utils = __webpack_require__(2);
  63. var bind = __webpack_require__(3);
  64. var Axios = __webpack_require__(5);
  65. var defaults = __webpack_require__(6);
  66. /**
  67. * Create an instance of Axios
  68. *
  69. * @param {Object} defaultConfig The default config for the instance
  70. * @return {Axios} A new instance of Axios
  71. */
  72. function createInstance(defaultConfig) {
  73. var context = new Axios(defaultConfig);
  74. var instance = bind(Axios.prototype.request, context);
  75. // Copy axios.prototype to instance
  76. utils.extend(instance, Axios.prototype, context);
  77. // Copy context to instance
  78. utils.extend(instance, context);
  79. return instance;
  80. }
  81. // Create the default instance to be exported
  82. var axios = createInstance(defaults);
  83. // Expose Axios class to allow class inheritance
  84. axios.Axios = Axios;
  85. // Factory for creating new instances
  86. axios.create = function create(instanceConfig) {
  87. return createInstance(utils.merge(defaults, instanceConfig));
  88. };
  89. // Expose Cancel & CancelToken
  90. axios.Cancel = __webpack_require__(22);
  91. axios.CancelToken = __webpack_require__(23);
  92. axios.isCancel = __webpack_require__(19);
  93. // Expose all/spread
  94. axios.all = function all(promises) {
  95. return Promise.all(promises);
  96. };
  97. axios.spread = __webpack_require__(24);
  98. module.exports = axios;
  99. // Allow use of default import syntax in TypeScript
  100. module.exports.default = axios;
  101. /***/ }),
  102. /* 2 */
  103. /***/ (function(module, exports, __webpack_require__) {
  104. 'use strict';
  105. var bind = __webpack_require__(3);
  106. var isBuffer = __webpack_require__(4);
  107. /*global toString:true*/
  108. // utils is a library of generic helper functions non-specific to axios
  109. var toString = Object.prototype.toString;
  110. /**
  111. * Determine if a value is an Array
  112. *
  113. * @param {Object} val The value to test
  114. * @returns {boolean} True if value is an Array, otherwise false
  115. */
  116. function isArray(val) {
  117. return toString.call(val) === '[object Array]';
  118. }
  119. /**
  120. * Determine if a value is an ArrayBuffer
  121. *
  122. * @param {Object} val The value to test
  123. * @returns {boolean} True if value is an ArrayBuffer, otherwise false
  124. */
  125. function isArrayBuffer(val) {
  126. return toString.call(val) === '[object ArrayBuffer]';
  127. }
  128. /**
  129. * Determine if a value is a FormData
  130. *
  131. * @param {Object} val The value to test
  132. * @returns {boolean} True if value is an FormData, otherwise false
  133. */
  134. function isFormData(val) {
  135. return (typeof FormData !== 'undefined') && (val instanceof FormData);
  136. }
  137. /**
  138. * Determine if a value is a view on an ArrayBuffer
  139. *
  140. * @param {Object} val The value to test
  141. * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
  142. */
  143. function isArrayBufferView(val) {
  144. var result;
  145. if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
  146. result = ArrayBuffer.isView(val);
  147. } else {
  148. result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
  149. }
  150. return result;
  151. }
  152. /**
  153. * Determine if a value is a String
  154. *
  155. * @param {Object} val The value to test
  156. * @returns {boolean} True if value is a String, otherwise false
  157. */
  158. function isString(val) {
  159. return typeof val === 'string';
  160. }
  161. /**
  162. * Determine if a value is a Number
  163. *
  164. * @param {Object} val The value to test
  165. * @returns {boolean} True if value is a Number, otherwise false
  166. */
  167. function isNumber(val) {
  168. return typeof val === 'number';
  169. }
  170. /**
  171. * Determine if a value is undefined
  172. *
  173. * @param {Object} val The value to test
  174. * @returns {boolean} True if the value is undefined, otherwise false
  175. */
  176. function isUndefined(val) {
  177. return typeof val === 'undefined';
  178. }
  179. /**
  180. * Determine if a value is an Object
  181. *
  182. * @param {Object} val The value to test
  183. * @returns {boolean} True if value is an Object, otherwise false
  184. */
  185. function isObject(val) {
  186. return val !== null && typeof val === 'object';
  187. }
  188. /**
  189. * Determine if a value is a Date
  190. *
  191. * @param {Object} val The value to test
  192. * @returns {boolean} True if value is a Date, otherwise false
  193. */
  194. function isDate(val) {
  195. return toString.call(val) === '[object Date]';
  196. }
  197. /**
  198. * Determine if a value is a File
  199. *
  200. * @param {Object} val The value to test
  201. * @returns {boolean} True if value is a File, otherwise false
  202. */
  203. function isFile(val) {
  204. return toString.call(val) === '[object File]';
  205. }
  206. /**
  207. * Determine if a value is a Blob
  208. *
  209. * @param {Object} val The value to test
  210. * @returns {boolean} True if value is a Blob, otherwise false
  211. */
  212. function isBlob(val) {
  213. return toString.call(val) === '[object Blob]';
  214. }
  215. /**
  216. * Determine if a value is a Function
  217. *
  218. * @param {Object} val The value to test
  219. * @returns {boolean} True if value is a Function, otherwise false
  220. */
  221. function isFunction(val) {
  222. return toString.call(val) === '[object Function]';
  223. }
  224. /**
  225. * Determine if a value is a Stream
  226. *
  227. * @param {Object} val The value to test
  228. * @returns {boolean} True if value is a Stream, otherwise false
  229. */
  230. function isStream(val) {
  231. return isObject(val) && isFunction(val.pipe);
  232. }
  233. /**
  234. * Determine if a value is a URLSearchParams object
  235. *
  236. * @param {Object} val The value to test
  237. * @returns {boolean} True if value is a URLSearchParams object, otherwise false
  238. */
  239. function isURLSearchParams(val) {
  240. return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
  241. }
  242. /**
  243. * Trim excess whitespace off the beginning and end of a string
  244. *
  245. * @param {String} str The String to trim
  246. * @returns {String} The String freed of excess whitespace
  247. */
  248. function trim(str) {
  249. return str.replace(/^\s*/, '').replace(/\s*$/, '');
  250. }
  251. /**
  252. * Determine if we're running in a standard browser environment
  253. *
  254. * This allows axios to run in a web worker, and react-native.
  255. * Both environments support XMLHttpRequest, but not fully standard globals.
  256. *
  257. * web workers:
  258. * typeof window -> undefined
  259. * typeof document -> undefined
  260. *
  261. * react-native:
  262. * navigator.product -> 'ReactNative'
  263. */
  264. function isStandardBrowserEnv() {
  265. if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
  266. return false;
  267. }
  268. return (
  269. typeof window !== 'undefined' &&
  270. typeof document !== 'undefined'
  271. );
  272. }
  273. /**
  274. * Iterate over an Array or an Object invoking a function for each item.
  275. *
  276. * If `obj` is an Array callback will be called passing
  277. * the value, index, and complete array for each item.
  278. *
  279. * If 'obj' is an Object callback will be called passing
  280. * the value, key, and complete object for each property.
  281. *
  282. * @param {Object|Array} obj The object to iterate
  283. * @param {Function} fn The callback to invoke for each item
  284. */
  285. function forEach(obj, fn) {
  286. // Don't bother if no value provided
  287. if (obj === null || typeof obj === 'undefined') {
  288. return;
  289. }
  290. // Force an array if not already something iterable
  291. if (typeof obj !== 'object') {
  292. /*eslint no-param-reassign:0*/
  293. obj = [obj];
  294. }
  295. if (isArray(obj)) {
  296. // Iterate over array values
  297. for (var i = 0, l = obj.length; i < l; i++) {
  298. fn.call(null, obj[i], i, obj);
  299. }
  300. } else {
  301. // Iterate over object keys
  302. for (var key in obj) {
  303. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  304. fn.call(null, obj[key], key, obj);
  305. }
  306. }
  307. }
  308. }
  309. /**
  310. * Accepts varargs expecting each argument to be an object, then
  311. * immutably merges the properties of each object and returns result.
  312. *
  313. * When multiple objects contain the same key the later object in
  314. * the arguments list will take precedence.
  315. *
  316. * Example:
  317. *
  318. * ```js
  319. * var result = merge({foo: 123}, {foo: 456});
  320. * console.log(result.foo); // outputs 456
  321. * ```
  322. *
  323. * @param {Object} obj1 Object to merge
  324. * @returns {Object} Result of all merge properties
  325. */
  326. function merge(/* obj1, obj2, obj3, ... */) {
  327. var result = {};
  328. function assignValue(val, key) {
  329. if (typeof result[key] === 'object' && typeof val === 'object') {
  330. result[key] = merge(result[key], val);
  331. } else {
  332. result[key] = val;
  333. }
  334. }
  335. for (var i = 0, l = arguments.length; i < l; i++) {
  336. forEach(arguments[i], assignValue);
  337. }
  338. return result;
  339. }
  340. /**
  341. * Extends object a by mutably adding to it the properties of object b.
  342. *
  343. * @param {Object} a The object to be extended
  344. * @param {Object} b The object to copy properties from
  345. * @param {Object} thisArg The object to bind function to
  346. * @return {Object} The resulting value of object a
  347. */
  348. function extend(a, b, thisArg) {
  349. forEach(b, function assignValue(val, key) {
  350. if (thisArg && typeof val === 'function') {
  351. a[key] = bind(val, thisArg);
  352. } else {
  353. a[key] = val;
  354. }
  355. });
  356. return a;
  357. }
  358. module.exports = {
  359. isArray: isArray,
  360. isArrayBuffer: isArrayBuffer,
  361. isBuffer: isBuffer,
  362. isFormData: isFormData,
  363. isArrayBufferView: isArrayBufferView,
  364. isString: isString,
  365. isNumber: isNumber,
  366. isObject: isObject,
  367. isUndefined: isUndefined,
  368. isDate: isDate,
  369. isFile: isFile,
  370. isBlob: isBlob,
  371. isFunction: isFunction,
  372. isStream: isStream,
  373. isURLSearchParams: isURLSearchParams,
  374. isStandardBrowserEnv: isStandardBrowserEnv,
  375. forEach: forEach,
  376. merge: merge,
  377. extend: extend,
  378. trim: trim
  379. };
  380. /***/ }),
  381. /* 3 */
  382. /***/ (function(module, exports) {
  383. 'use strict';
  384. module.exports = function bind(fn, thisArg) {
  385. return function wrap() {
  386. var args = new Array(arguments.length);
  387. for (var i = 0; i < args.length; i++) {
  388. args[i] = arguments[i];
  389. }
  390. return fn.apply(thisArg, args);
  391. };
  392. };
  393. /***/ }),
  394. /* 4 */
  395. /***/ (function(module, exports) {
  396. /*!
  397. * Determine if an object is a Buffer
  398. *
  399. * @author Feross Aboukhadijeh <https://feross.org>
  400. * @license MIT
  401. */
  402. module.exports = function isBuffer (obj) {
  403. return obj != null && obj.constructor != null &&
  404. typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  405. }
  406. /***/ }),
  407. /* 5 */
  408. /***/ (function(module, exports, __webpack_require__) {
  409. 'use strict';
  410. var defaults = __webpack_require__(6);
  411. var utils = __webpack_require__(2);
  412. var InterceptorManager = __webpack_require__(16);
  413. var dispatchRequest = __webpack_require__(17);
  414. /**
  415. * Create a new instance of Axios
  416. *
  417. * @param {Object} instanceConfig The default config for the instance
  418. */
  419. function Axios(instanceConfig) {
  420. this.defaults = instanceConfig;
  421. this.interceptors = {
  422. request: new InterceptorManager(),
  423. response: new InterceptorManager()
  424. };
  425. }
  426. /**
  427. * Dispatch a request
  428. *
  429. * @param {Object} config The config specific for this request (merged with this.defaults)
  430. */
  431. Axios.prototype.request = function request(config) {
  432. /*eslint no-param-reassign:0*/
  433. // Allow for axios('example/url'[, config]) a la fetch API
  434. if (typeof config === 'string') {
  435. config = utils.merge({
  436. url: arguments[0]
  437. }, arguments[1]);
  438. }
  439. config = utils.merge(defaults, {method: 'get'}, this.defaults, config);
  440. config.method = config.method.toLowerCase();
  441. // Hook up interceptors middleware
  442. var chain = [dispatchRequest, undefined];
  443. var promise = Promise.resolve(config);
  444. this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
  445. chain.unshift(interceptor.fulfilled, interceptor.rejected);
  446. });
  447. this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
  448. chain.push(interceptor.fulfilled, interceptor.rejected);
  449. });
  450. while (chain.length) {
  451. promise = promise.then(chain.shift(), chain.shift());
  452. }
  453. return promise;
  454. };
  455. // Provide aliases for supported request methods
  456. utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
  457. /*eslint func-names:0*/
  458. Axios.prototype[method] = function(url, config) {
  459. return this.request(utils.merge(config || {}, {
  460. method: method,
  461. url: url
  462. }));
  463. };
  464. });
  465. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  466. /*eslint func-names:0*/
  467. Axios.prototype[method] = function(url, data, config) {
  468. return this.request(utils.merge(config || {}, {
  469. method: method,
  470. url: url,
  471. data: data
  472. }));
  473. };
  474. });
  475. module.exports = Axios;
  476. /***/ }),
  477. /* 6 */
  478. /***/ (function(module, exports, __webpack_require__) {
  479. 'use strict';
  480. var utils = __webpack_require__(2);
  481. var normalizeHeaderName = __webpack_require__(7);
  482. var DEFAULT_CONTENT_TYPE = {
  483. 'Content-Type': 'application/x-www-form-urlencoded'
  484. };
  485. function setContentTypeIfUnset(headers, value) {
  486. if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
  487. headers['Content-Type'] = value;
  488. }
  489. }
  490. function getDefaultAdapter() {
  491. var adapter;
  492. if (typeof XMLHttpRequest !== 'undefined') {
  493. // For browsers use XHR adapter
  494. adapter = __webpack_require__(8);
  495. } else if (typeof process !== 'undefined') {
  496. // For node use HTTP adapter
  497. adapter = __webpack_require__(8);
  498. }
  499. return adapter;
  500. }
  501. var defaults = {
  502. adapter: getDefaultAdapter(),
  503. transformRequest: [function transformRequest(data, headers) {
  504. normalizeHeaderName(headers, 'Content-Type');
  505. if (utils.isFormData(data) ||
  506. utils.isArrayBuffer(data) ||
  507. utils.isBuffer(data) ||
  508. utils.isStream(data) ||
  509. utils.isFile(data) ||
  510. utils.isBlob(data)
  511. ) {
  512. return data;
  513. }
  514. if (utils.isArrayBufferView(data)) {
  515. return data.buffer;
  516. }
  517. if (utils.isURLSearchParams(data)) {
  518. setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
  519. return data.toString();
  520. }
  521. if (utils.isObject(data)) {
  522. setContentTypeIfUnset(headers, 'application/json;charset=utf-8');
  523. return JSON.stringify(data);
  524. }
  525. return data;
  526. }],
  527. transformResponse: [function transformResponse(data) {
  528. /*eslint no-param-reassign:0*/
  529. if (typeof data === 'string') {
  530. try {
  531. data = JSON.parse(data);
  532. } catch (e) { /* Ignore */ }
  533. }
  534. return data;
  535. }],
  536. /**
  537. * A timeout in milliseconds to abort a request. If set to 0 (default) a
  538. * timeout is not created.
  539. */
  540. timeout: 0,
  541. xsrfCookieName: 'XSRF-TOKEN',
  542. xsrfHeaderName: 'X-XSRF-TOKEN',
  543. maxContentLength: -1,
  544. validateStatus: function validateStatus(status) {
  545. return status >= 200 && status < 300;
  546. }
  547. };
  548. defaults.headers = {
  549. common: {
  550. 'Accept': 'application/json, text/plain, */*'
  551. }
  552. };
  553. utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
  554. defaults.headers[method] = {};
  555. });
  556. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  557. defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
  558. });
  559. module.exports = defaults;
  560. /***/ }),
  561. /* 7 */
  562. /***/ (function(module, exports, __webpack_require__) {
  563. 'use strict';
  564. var utils = __webpack_require__(2);
  565. module.exports = function normalizeHeaderName(headers, normalizedName) {
  566. utils.forEach(headers, function processHeader(value, name) {
  567. if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
  568. headers[normalizedName] = value;
  569. delete headers[name];
  570. }
  571. });
  572. };
  573. /***/ }),
  574. /* 8 */
  575. /***/ (function(module, exports, __webpack_require__) {
  576. 'use strict';
  577. var utils = __webpack_require__(2);
  578. var settle = __webpack_require__(9);
  579. var buildURL = __webpack_require__(12);
  580. var parseHeaders = __webpack_require__(13);
  581. var isURLSameOrigin = __webpack_require__(14);
  582. var createError = __webpack_require__(10);
  583. module.exports = function xhrAdapter(config) {
  584. return new Promise(function dispatchXhrRequest(resolve, reject) {
  585. var requestData = config.data;
  586. var requestHeaders = config.headers;
  587. if (utils.isFormData(requestData)) {
  588. delete requestHeaders['Content-Type']; // Let the browser set it
  589. }
  590. var request = new XMLHttpRequest();
  591. // HTTP basic authentication
  592. if (config.auth) {
  593. var username = config.auth.username || '';
  594. var password = config.auth.password || '';
  595. requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
  596. }
  597. request.open(config.method.toUpperCase(), buildURL(config.url, config.params, config.paramsSerializer), true);
  598. // Set the request timeout in MS
  599. request.timeout = config.timeout;
  600. // Listen for ready state
  601. request.onreadystatechange = function handleLoad() {
  602. if (!request || request.readyState !== 4) {
  603. return;
  604. }
  605. // The request errored out and we didn't get a response, this will be
  606. // handled by onerror instead
  607. // With one exception: request that using file: protocol, most browsers
  608. // will return status as 0 even though it's a successful request
  609. if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
  610. return;
  611. }
  612. // Prepare the response
  613. var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
  614. var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
  615. var response = {
  616. data: responseData,
  617. status: request.status,
  618. statusText: request.statusText,
  619. headers: responseHeaders,
  620. config: config,
  621. request: request
  622. };
  623. settle(resolve, reject, response);
  624. // Clean up request
  625. request = null;
  626. };
  627. // Handle low level network errors
  628. request.onerror = function handleError() {
  629. // Real errors are hidden from us by the browser
  630. // onerror should only fire if it's a network error
  631. reject(createError('Network Error', config, null, request));
  632. // Clean up request
  633. request = null;
  634. };
  635. // Handle timeout
  636. request.ontimeout = function handleTimeout() {
  637. reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED',
  638. request));
  639. // Clean up request
  640. request = null;
  641. };
  642. // Add xsrf header
  643. // This is only done if running in a standard browser environment.
  644. // Specifically not if we're in a web worker, or react-native.
  645. if (utils.isStandardBrowserEnv()) {
  646. var cookies = __webpack_require__(15);
  647. // Add xsrf header
  648. var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ?
  649. cookies.read(config.xsrfCookieName) :
  650. undefined;
  651. if (xsrfValue) {
  652. requestHeaders[config.xsrfHeaderName] = xsrfValue;
  653. }
  654. }
  655. // Add headers to the request
  656. if ('setRequestHeader' in request) {
  657. utils.forEach(requestHeaders, function setRequestHeader(val, key) {
  658. if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
  659. // Remove Content-Type if data is undefined
  660. delete requestHeaders[key];
  661. } else {
  662. // Otherwise add header to the request
  663. request.setRequestHeader(key, val);
  664. }
  665. });
  666. }
  667. // Add withCredentials to request if needed
  668. if (config.withCredentials) {
  669. request.withCredentials = true;
  670. }
  671. // Add responseType to request if needed
  672. if (config.responseType) {
  673. try {
  674. request.responseType = config.responseType;
  675. } catch (e) {
  676. // Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.
  677. // But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.
  678. if (config.responseType !== 'json') {
  679. throw e;
  680. }
  681. }
  682. }
  683. // Handle progress if needed
  684. if (typeof config.onDownloadProgress === 'function') {
  685. request.addEventListener('progress', config.onDownloadProgress);
  686. }
  687. // Not all browsers support upload events
  688. if (typeof config.onUploadProgress === 'function' && request.upload) {
  689. request.upload.addEventListener('progress', config.onUploadProgress);
  690. }
  691. if (config.cancelToken) {
  692. // Handle cancellation
  693. config.cancelToken.promise.then(function onCanceled(cancel) {
  694. if (!request) {
  695. return;
  696. }
  697. request.abort();
  698. reject(cancel);
  699. // Clean up request
  700. request = null;
  701. });
  702. }
  703. if (requestData === undefined) {
  704. requestData = null;
  705. }
  706. // Send the request
  707. request.send(requestData);
  708. });
  709. };
  710. /***/ }),
  711. /* 9 */
  712. /***/ (function(module, exports, __webpack_require__) {
  713. 'use strict';
  714. var createError = __webpack_require__(10);
  715. /**
  716. * Resolve or reject a Promise based on response status.
  717. *
  718. * @param {Function} resolve A function that resolves the promise.
  719. * @param {Function} reject A function that rejects the promise.
  720. * @param {object} response The response.
  721. */
  722. module.exports = function settle(resolve, reject, response) {
  723. var validateStatus = response.config.validateStatus;
  724. // Note: status is not exposed by XDomainRequest
  725. if (!response.status || !validateStatus || validateStatus(response.status)) {
  726. resolve(response);
  727. } else {
  728. reject(createError(
  729. 'Request failed with status code ' + response.status,
  730. response.config,
  731. null,
  732. response.request,
  733. response
  734. ));
  735. }
  736. };
  737. /***/ }),
  738. /* 10 */
  739. /***/ (function(module, exports, __webpack_require__) {
  740. 'use strict';
  741. var enhanceError = __webpack_require__(11);
  742. /**
  743. * Create an Error with the specified message, config, error code, request and response.
  744. *
  745. * @param {string} message The error message.
  746. * @param {Object} config The config.
  747. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  748. * @param {Object} [request] The request.
  749. * @param {Object} [response] The response.
  750. * @returns {Error} The created error.
  751. */
  752. module.exports = function createError(message, config, code, request, response) {
  753. var error = new Error(message);
  754. return enhanceError(error, config, code, request, response);
  755. };
  756. /***/ }),
  757. /* 11 */
  758. /***/ (function(module, exports) {
  759. 'use strict';
  760. /**
  761. * Update an Error with the specified config, error code, and response.
  762. *
  763. * @param {Error} error The error to update.
  764. * @param {Object} config The config.
  765. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  766. * @param {Object} [request] The request.
  767. * @param {Object} [response] The response.
  768. * @returns {Error} The error.
  769. */
  770. module.exports = function enhanceError(error, config, code, request, response) {
  771. error.config = config;
  772. if (code) {
  773. error.code = code;
  774. }
  775. error.request = request;
  776. error.response = response;
  777. return error;
  778. };
  779. /***/ }),
  780. /* 12 */
  781. /***/ (function(module, exports, __webpack_require__) {
  782. 'use strict';
  783. var utils = __webpack_require__(2);
  784. function encode(val) {
  785. return encodeURIComponent(val).
  786. replace(/%40/gi, '@').
  787. replace(/%3A/gi, ':').
  788. replace(/%24/g, '$').
  789. replace(/%2C/gi, ',').
  790. replace(/%20/g, '+').
  791. replace(/%5B/gi, '[').
  792. replace(/%5D/gi, ']');
  793. }
  794. /**
  795. * Build a URL by appending params to the end
  796. *
  797. * @param {string} url The base of the url (e.g., http://www.google.com)
  798. * @param {object} [params] The params to be appended
  799. * @returns {string} The formatted url
  800. */
  801. module.exports = function buildURL(url, params, paramsSerializer) {
  802. /*eslint no-param-reassign:0*/
  803. if (!params) {
  804. return url;
  805. }
  806. var serializedParams;
  807. if (paramsSerializer) {
  808. serializedParams = paramsSerializer(params);
  809. } else if (utils.isURLSearchParams(params)) {
  810. serializedParams = params.toString();
  811. } else {
  812. var parts = [];
  813. utils.forEach(params, function serialize(val, key) {
  814. if (val === null || typeof val === 'undefined') {
  815. return;
  816. }
  817. if (utils.isArray(val)) {
  818. key = key + '[]';
  819. } else {
  820. val = [val];
  821. }
  822. utils.forEach(val, function parseValue(v) {
  823. if (utils.isDate(v)) {
  824. v = v.toISOString();
  825. } else if (utils.isObject(v)) {
  826. v = JSON.stringify(v);
  827. }
  828. parts.push(encode(key) + '=' + encode(v));
  829. });
  830. });
  831. serializedParams = parts.join('&');
  832. }
  833. if (serializedParams) {
  834. url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
  835. }
  836. return url;
  837. };
  838. /***/ }),
  839. /* 13 */
  840. /***/ (function(module, exports, __webpack_require__) {
  841. 'use strict';
  842. var utils = __webpack_require__(2);
  843. // Headers whose duplicates are ignored by node
  844. // c.f. https://nodejs.org/api/http.html#http_message_headers
  845. var ignoreDuplicateOf = [
  846. 'age', 'authorization', 'content-length', 'content-type', 'etag',
  847. 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
  848. 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
  849. 'referer', 'retry-after', 'user-agent'
  850. ];
  851. /**
  852. * Parse headers into an object
  853. *
  854. * ```
  855. * Date: Wed, 27 Aug 2014 08:58:49 GMT
  856. * Content-Type: application/json
  857. * Connection: keep-alive
  858. * Transfer-Encoding: chunked
  859. * ```
  860. *
  861. * @param {String} headers Headers needing to be parsed
  862. * @returns {Object} Headers parsed into an object
  863. */
  864. module.exports = function parseHeaders(headers) {
  865. var parsed = {};
  866. var key;
  867. var val;
  868. var i;
  869. if (!headers) { return parsed; }
  870. utils.forEach(headers.split('\n'), function parser(line) {
  871. i = line.indexOf(':');
  872. key = utils.trim(line.substr(0, i)).toLowerCase();
  873. val = utils.trim(line.substr(i + 1));
  874. if (key) {
  875. if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
  876. return;
  877. }
  878. if (key === 'set-cookie') {
  879. parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
  880. } else {
  881. parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
  882. }
  883. }
  884. });
  885. return parsed;
  886. };
  887. /***/ }),
  888. /* 14 */
  889. /***/ (function(module, exports, __webpack_require__) {
  890. 'use strict';
  891. var utils = __webpack_require__(2);
  892. module.exports = (
  893. utils.isStandardBrowserEnv() ?
  894. // Standard browser envs have full support of the APIs needed to test
  895. // whether the request URL is of the same origin as current location.
  896. (function standardBrowserEnv() {
  897. var msie = /(msie|trident)/i.test(navigator.userAgent);
  898. var urlParsingNode = document.createElement('a');
  899. var originURL;
  900. /**
  901. * Parse a URL to discover it's components
  902. *
  903. * @param {String} url The URL to be parsed
  904. * @returns {Object}
  905. */
  906. function resolveURL(url) {
  907. var href = url;
  908. if (msie) {
  909. // IE needs attribute set twice to normalize properties
  910. urlParsingNode.setAttribute('href', href);
  911. href = urlParsingNode.href;
  912. }
  913. urlParsingNode.setAttribute('href', href);
  914. // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
  915. return {
  916. href: urlParsingNode.href,
  917. protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
  918. host: urlParsingNode.host,
  919. search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
  920. hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
  921. hostname: urlParsingNode.hostname,
  922. port: urlParsingNode.port,
  923. pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
  924. urlParsingNode.pathname :
  925. '/' + urlParsingNode.pathname
  926. };
  927. }
  928. originURL = resolveURL(window.location.href);
  929. /**
  930. * Determine if a URL shares the same origin as the current location
  931. *
  932. * @param {String} requestURL The URL to test
  933. * @returns {boolean} True if URL shares the same origin, otherwise false
  934. */
  935. return function isURLSameOrigin(requestURL) {
  936. var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
  937. return (parsed.protocol === originURL.protocol &&
  938. parsed.host === originURL.host);
  939. };
  940. })() :
  941. // Non standard browser envs (web workers, react-native) lack needed support.
  942. (function nonStandardBrowserEnv() {
  943. return function isURLSameOrigin() {
  944. return true;
  945. };
  946. })()
  947. );
  948. /***/ }),
  949. /* 15 */
  950. /***/ (function(module, exports, __webpack_require__) {
  951. 'use strict';
  952. var utils = __webpack_require__(2);
  953. module.exports = (
  954. utils.isStandardBrowserEnv() ?
  955. // Standard browser envs support document.cookie
  956. (function standardBrowserEnv() {
  957. return {
  958. write: function write(name, value, expires, path, domain, secure) {
  959. var cookie = [];
  960. cookie.push(name + '=' + encodeURIComponent(value));
  961. if (utils.isNumber(expires)) {
  962. cookie.push('expires=' + new Date(expires).toGMTString());
  963. }
  964. if (utils.isString(path)) {
  965. cookie.push('path=' + path);
  966. }
  967. if (utils.isString(domain)) {
  968. cookie.push('domain=' + domain);
  969. }
  970. if (secure === true) {
  971. cookie.push('secure');
  972. }
  973. document.cookie = cookie.join('; ');
  974. },
  975. read: function read(name) {
  976. var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
  977. return (match ? decodeURIComponent(match[3]) : null);
  978. },
  979. remove: function remove(name) {
  980. this.write(name, '', Date.now() - 86400000);
  981. }
  982. };
  983. })() :
  984. // Non standard browser env (web workers, react-native) lack needed support.
  985. (function nonStandardBrowserEnv() {
  986. return {
  987. write: function write() {},
  988. read: function read() { return null; },
  989. remove: function remove() {}
  990. };
  991. })()
  992. );
  993. /***/ }),
  994. /* 16 */
  995. /***/ (function(module, exports, __webpack_require__) {
  996. 'use strict';
  997. var utils = __webpack_require__(2);
  998. function InterceptorManager() {
  999. this.handlers = [];
  1000. }
  1001. /**
  1002. * Add a new interceptor to the stack
  1003. *
  1004. * @param {Function} fulfilled The function to handle `then` for a `Promise`
  1005. * @param {Function} rejected The function to handle `reject` for a `Promise`
  1006. *
  1007. * @return {Number} An ID used to remove interceptor later
  1008. */
  1009. InterceptorManager.prototype.use = function use(fulfilled, rejected) {
  1010. this.handlers.push({
  1011. fulfilled: fulfilled,
  1012. rejected: rejected
  1013. });
  1014. return this.handlers.length - 1;
  1015. };
  1016. /**
  1017. * Remove an interceptor from the stack
  1018. *
  1019. * @param {Number} id The ID that was returned by `use`
  1020. */
  1021. InterceptorManager.prototype.eject = function eject(id) {
  1022. if (this.handlers[id]) {
  1023. this.handlers[id] = null;
  1024. }
  1025. };
  1026. /**
  1027. * Iterate over all the registered interceptors
  1028. *
  1029. * This method is particularly useful for skipping over any
  1030. * interceptors that may have become `null` calling `eject`.
  1031. *
  1032. * @param {Function} fn The function to call for each interceptor
  1033. */
  1034. InterceptorManager.prototype.forEach = function forEach(fn) {
  1035. utils.forEach(this.handlers, function forEachHandler(h) {
  1036. if (h !== null) {
  1037. fn(h);
  1038. }
  1039. });
  1040. };
  1041. module.exports = InterceptorManager;
  1042. /***/ }),
  1043. /* 17 */
  1044. /***/ (function(module, exports, __webpack_require__) {
  1045. 'use strict';
  1046. var utils = __webpack_require__(2);
  1047. var transformData = __webpack_require__(18);
  1048. var isCancel = __webpack_require__(19);
  1049. var defaults = __webpack_require__(6);
  1050. var isAbsoluteURL = __webpack_require__(20);
  1051. var combineURLs = __webpack_require__(21);
  1052. /**
  1053. * Throws a `Cancel` if cancellation has been requested.
  1054. */
  1055. function throwIfCancellationRequested(config) {
  1056. if (config.cancelToken) {
  1057. config.cancelToken.throwIfRequested();
  1058. }
  1059. }
  1060. /**
  1061. * Dispatch a request to the server using the configured adapter.
  1062. *
  1063. * @param {object} config The config that is to be used for the request
  1064. * @returns {Promise} The Promise to be fulfilled
  1065. */
  1066. module.exports = function dispatchRequest(config) {
  1067. throwIfCancellationRequested(config);
  1068. // Support baseURL config
  1069. if (config.baseURL && !isAbsoluteURL(config.url)) {
  1070. config.url = combineURLs(config.baseURL, config.url);
  1071. }
  1072. // Ensure headers exist
  1073. config.headers = config.headers || {};
  1074. // Transform request data
  1075. config.data = transformData(
  1076. config.data,
  1077. config.headers,
  1078. config.transformRequest
  1079. );
  1080. // Flatten headers
  1081. config.headers = utils.merge(
  1082. config.headers.common || {},
  1083. config.headers[config.method] || {},
  1084. config.headers || {}
  1085. );
  1086. utils.forEach(
  1087. ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
  1088. function cleanHeaderConfig(method) {
  1089. delete config.headers[method];
  1090. }
  1091. );
  1092. var adapter = config.adapter || defaults.adapter;
  1093. return adapter(config).then(function onAdapterResolution(response) {
  1094. throwIfCancellationRequested(config);
  1095. // Transform response data
  1096. response.data = transformData(
  1097. response.data,
  1098. response.headers,
  1099. config.transformResponse
  1100. );
  1101. return response;
  1102. }, function onAdapterRejection(reason) {
  1103. if (!isCancel(reason)) {
  1104. throwIfCancellationRequested(config);
  1105. // Transform response data
  1106. if (reason && reason.response) {
  1107. reason.response.data = transformData(
  1108. reason.response.data,
  1109. reason.response.headers,
  1110. config.transformResponse
  1111. );
  1112. }
  1113. }
  1114. return Promise.reject(reason);
  1115. });
  1116. };
  1117. /***/ }),
  1118. /* 18 */
  1119. /***/ (function(module, exports, __webpack_require__) {
  1120. 'use strict';
  1121. var utils = __webpack_require__(2);
  1122. /**
  1123. * Transform the data for a request or a response
  1124. *
  1125. * @param {Object|String} data The data to be transformed
  1126. * @param {Array} headers The headers for the request or response
  1127. * @param {Array|Function} fns A single function or Array of functions
  1128. * @returns {*} The resulting transformed data
  1129. */
  1130. module.exports = function transformData(data, headers, fns) {
  1131. /*eslint no-param-reassign:0*/
  1132. utils.forEach(fns, function transform(fn) {
  1133. data = fn(data, headers);
  1134. });
  1135. return data;
  1136. };
  1137. /***/ }),
  1138. /* 19 */
  1139. /***/ (function(module, exports) {
  1140. 'use strict';
  1141. module.exports = function isCancel(value) {
  1142. return !!(value && value.__CANCEL__);
  1143. };
  1144. /***/ }),
  1145. /* 20 */
  1146. /***/ (function(module, exports) {
  1147. 'use strict';
  1148. /**
  1149. * Determines whether the specified URL is absolute
  1150. *
  1151. * @param {string} url The URL to test
  1152. * @returns {boolean} True if the specified URL is absolute, otherwise false
  1153. */
  1154. module.exports = function isAbsoluteURL(url) {
  1155. // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
  1156. // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
  1157. // by any combination of letters, digits, plus, period, or hyphen.
  1158. return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
  1159. };
  1160. /***/ }),
  1161. /* 21 */
  1162. /***/ (function(module, exports) {
  1163. 'use strict';
  1164. /**
  1165. * Creates a new URL by combining the specified URLs
  1166. *
  1167. * @param {string} baseURL The base URL
  1168. * @param {string} relativeURL The relative URL
  1169. * @returns {string} The combined URL
  1170. */
  1171. module.exports = function combineURLs(baseURL, relativeURL) {
  1172. return relativeURL
  1173. ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
  1174. : baseURL;
  1175. };
  1176. /***/ }),
  1177. /* 22 */
  1178. /***/ (function(module, exports) {
  1179. 'use strict';
  1180. /**
  1181. * A `Cancel` is an object that is thrown when an operation is canceled.
  1182. *
  1183. * @class
  1184. * @param {string=} message The message.
  1185. */
  1186. function Cancel(message) {
  1187. this.message = message;
  1188. }
  1189. Cancel.prototype.toString = function toString() {
  1190. return 'Cancel' + (this.message ? ': ' + this.message : '');
  1191. };
  1192. Cancel.prototype.__CANCEL__ = true;
  1193. module.exports = Cancel;
  1194. /***/ }),
  1195. /* 23 */
  1196. /***/ (function(module, exports, __webpack_require__) {
  1197. 'use strict';
  1198. var Cancel = __webpack_require__(22);
  1199. /**
  1200. * A `CancelToken` is an object that can be used to request cancellation of an operation.
  1201. *
  1202. * @class
  1203. * @param {Function} executor The executor function.
  1204. */
  1205. function CancelToken(executor) {
  1206. if (typeof executor !== 'function') {
  1207. throw new TypeError('executor must be a function.');
  1208. }
  1209. var resolvePromise;
  1210. this.promise = new Promise(function promiseExecutor(resolve) {
  1211. resolvePromise = resolve;
  1212. });
  1213. var token = this;
  1214. executor(function cancel(message) {
  1215. if (token.reason) {
  1216. // Cancellation has already been requested
  1217. return;
  1218. }
  1219. token.reason = new Cancel(message);
  1220. resolvePromise(token.reason);
  1221. });
  1222. }
  1223. /**
  1224. * Throws a `Cancel` if cancellation has been requested.
  1225. */
  1226. CancelToken.prototype.throwIfRequested = function throwIfRequested() {
  1227. if (this.reason) {
  1228. throw this.reason;
  1229. }
  1230. };
  1231. /**
  1232. * Returns an object that contains a new `CancelToken` and a function that, when called,
  1233. * cancels the `CancelToken`.
  1234. */
  1235. CancelToken.source = function source() {
  1236. var cancel;
  1237. var token = new CancelToken(function executor(c) {
  1238. cancel = c;
  1239. });
  1240. return {
  1241. token: token,
  1242. cancel: cancel
  1243. };
  1244. };
  1245. module.exports = CancelToken;
  1246. /***/ }),
  1247. /* 24 */
  1248. /***/ (function(module, exports) {
  1249. 'use strict';
  1250. /**
  1251. * Syntactic sugar for invoking a function and expanding an array for arguments.
  1252. *
  1253. * Common use case would be to use `Function.prototype.apply`.
  1254. *
  1255. * ```js
  1256. * function f(x, y, z) {}
  1257. * var args = [1, 2, 3];
  1258. * f.apply(null, args);
  1259. * ```
  1260. *
  1261. * With `spread` this example can be re-written.
  1262. *
  1263. * ```js
  1264. * spread(function(x, y, z) {})([1, 2, 3]);
  1265. * ```
  1266. *
  1267. * @param {Function} callback
  1268. * @returns {Function}
  1269. */
  1270. module.exports = function spread(callback) {
  1271. return function wrap(arr) {
  1272. return callback.apply(null, arr);
  1273. };
  1274. };
  1275. /***/ })
  1276. /******/ ])
  1277. });
  1278. ;
  1279. //# sourceMappingURL=axios.map