axios.js 36 KB

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