| 1 | /*! Axios v1.16.1 Copyright (c) 2026 Matt Zabriskie and contributors */
|
|---|
| 2 | 'use strict';
|
|---|
| 3 |
|
|---|
| 4 | var FormData$1 = require('form-data');
|
|---|
| 5 | var crypto = require('crypto');
|
|---|
| 6 | var url = require('url');
|
|---|
| 7 | var HttpsProxyAgent = require('https-proxy-agent');
|
|---|
| 8 | var http = require('http');
|
|---|
| 9 | var https = require('https');
|
|---|
| 10 | var http2 = require('http2');
|
|---|
| 11 | var util = require('util');
|
|---|
| 12 | var path = require('path');
|
|---|
| 13 | var followRedirects = require('follow-redirects');
|
|---|
| 14 | var zlib = require('zlib');
|
|---|
| 15 | var stream = require('stream');
|
|---|
| 16 | var events = require('events');
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * Create a bound version of a function with a specified `this` context
|
|---|
| 20 | *
|
|---|
| 21 | * @param {Function} fn - The function to bind
|
|---|
| 22 | * @param {*} thisArg - The value to be passed as the `this` parameter
|
|---|
| 23 | * @returns {Function} A new function that will call the original function with the specified `this` context
|
|---|
| 24 | */
|
|---|
| 25 | function bind(fn, thisArg) {
|
|---|
| 26 | return function wrap() {
|
|---|
| 27 | return fn.apply(thisArg, arguments);
|
|---|
| 28 | };
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | // utils is a library of generic helper functions non-specific to axios
|
|---|
| 32 |
|
|---|
| 33 | const {
|
|---|
| 34 | toString
|
|---|
| 35 | } = Object.prototype;
|
|---|
| 36 | const {
|
|---|
| 37 | getPrototypeOf
|
|---|
| 38 | } = Object;
|
|---|
| 39 | const {
|
|---|
| 40 | iterator,
|
|---|
| 41 | toStringTag
|
|---|
| 42 | } = Symbol;
|
|---|
| 43 | const kindOf = (cache => thing => {
|
|---|
| 44 | const str = toString.call(thing);
|
|---|
| 45 | return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
|---|
| 46 | })(Object.create(null));
|
|---|
| 47 | const kindOfTest = type => {
|
|---|
| 48 | type = type.toLowerCase();
|
|---|
| 49 | return thing => kindOf(thing) === type;
|
|---|
| 50 | };
|
|---|
| 51 | const typeOfTest = type => thing => typeof thing === type;
|
|---|
| 52 |
|
|---|
| 53 | /**
|
|---|
| 54 | * Determine if a value is a non-null object
|
|---|
| 55 | *
|
|---|
| 56 | * @param {Object} val The value to test
|
|---|
| 57 | *
|
|---|
| 58 | * @returns {boolean} True if value is an Array, otherwise false
|
|---|
| 59 | */
|
|---|
| 60 | const {
|
|---|
| 61 | isArray
|
|---|
| 62 | } = Array;
|
|---|
| 63 |
|
|---|
| 64 | /**
|
|---|
| 65 | * Determine if a value is undefined
|
|---|
| 66 | *
|
|---|
| 67 | * @param {*} val The value to test
|
|---|
| 68 | *
|
|---|
| 69 | * @returns {boolean} True if the value is undefined, otherwise false
|
|---|
| 70 | */
|
|---|
| 71 | const isUndefined = typeOfTest('undefined');
|
|---|
| 72 |
|
|---|
| 73 | /**
|
|---|
| 74 | * Determine if a value is a Buffer
|
|---|
| 75 | *
|
|---|
| 76 | * @param {*} val The value to test
|
|---|
| 77 | *
|
|---|
| 78 | * @returns {boolean} True if value is a Buffer, otherwise false
|
|---|
| 79 | */
|
|---|
| 80 | function isBuffer(val) {
|
|---|
| 81 | return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor) && isFunction$1(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | /**
|
|---|
| 85 | * Determine if a value is an ArrayBuffer
|
|---|
| 86 | *
|
|---|
| 87 | * @param {*} val The value to test
|
|---|
| 88 | *
|
|---|
| 89 | * @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
|---|
| 90 | */
|
|---|
| 91 | const isArrayBuffer = kindOfTest('ArrayBuffer');
|
|---|
| 92 |
|
|---|
| 93 | /**
|
|---|
| 94 | * Determine if a value is a view on an ArrayBuffer
|
|---|
| 95 | *
|
|---|
| 96 | * @param {*} val The value to test
|
|---|
| 97 | *
|
|---|
| 98 | * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
|---|
| 99 | */
|
|---|
| 100 | function isArrayBufferView(val) {
|
|---|
| 101 | let result;
|
|---|
| 102 | if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView) {
|
|---|
| 103 | result = ArrayBuffer.isView(val);
|
|---|
| 104 | } else {
|
|---|
| 105 | result = val && val.buffer && isArrayBuffer(val.buffer);
|
|---|
| 106 | }
|
|---|
| 107 | return result;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | /**
|
|---|
| 111 | * Determine if a value is a String
|
|---|
| 112 | *
|
|---|
| 113 | * @param {*} val The value to test
|
|---|
| 114 | *
|
|---|
| 115 | * @returns {boolean} True if value is a String, otherwise false
|
|---|
| 116 | */
|
|---|
| 117 | const isString = typeOfTest('string');
|
|---|
| 118 |
|
|---|
| 119 | /**
|
|---|
| 120 | * Determine if a value is a Function
|
|---|
| 121 | *
|
|---|
| 122 | * @param {*} val The value to test
|
|---|
| 123 | * @returns {boolean} True if value is a Function, otherwise false
|
|---|
| 124 | */
|
|---|
| 125 | const isFunction$1 = typeOfTest('function');
|
|---|
| 126 |
|
|---|
| 127 | /**
|
|---|
| 128 | * Determine if a value is a Number
|
|---|
| 129 | *
|
|---|
| 130 | * @param {*} val The value to test
|
|---|
| 131 | *
|
|---|
| 132 | * @returns {boolean} True if value is a Number, otherwise false
|
|---|
| 133 | */
|
|---|
| 134 | const isNumber = typeOfTest('number');
|
|---|
| 135 |
|
|---|
| 136 | /**
|
|---|
| 137 | * Determine if a value is an Object
|
|---|
| 138 | *
|
|---|
| 139 | * @param {*} thing The value to test
|
|---|
| 140 | *
|
|---|
| 141 | * @returns {boolean} True if value is an Object, otherwise false
|
|---|
| 142 | */
|
|---|
| 143 | const isObject = thing => thing !== null && typeof thing === 'object';
|
|---|
| 144 |
|
|---|
| 145 | /**
|
|---|
| 146 | * Determine if a value is a Boolean
|
|---|
| 147 | *
|
|---|
| 148 | * @param {*} thing The value to test
|
|---|
| 149 | * @returns {boolean} True if value is a Boolean, otherwise false
|
|---|
| 150 | */
|
|---|
| 151 | const isBoolean = thing => thing === true || thing === false;
|
|---|
| 152 |
|
|---|
| 153 | /**
|
|---|
| 154 | * Determine if a value is a plain Object
|
|---|
| 155 | *
|
|---|
| 156 | * @param {*} val The value to test
|
|---|
| 157 | *
|
|---|
| 158 | * @returns {boolean} True if value is a plain Object, otherwise false
|
|---|
| 159 | */
|
|---|
| 160 | const isPlainObject = val => {
|
|---|
| 161 | if (kindOf(val) !== 'object') {
|
|---|
| 162 | return false;
|
|---|
| 163 | }
|
|---|
| 164 | const prototype = getPrototypeOf(val);
|
|---|
| 165 | return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
|
|---|
| 166 | };
|
|---|
| 167 |
|
|---|
| 168 | /**
|
|---|
| 169 | * Determine if a value is an empty object (safely handles Buffers)
|
|---|
| 170 | *
|
|---|
| 171 | * @param {*} val The value to test
|
|---|
| 172 | *
|
|---|
| 173 | * @returns {boolean} True if value is an empty object, otherwise false
|
|---|
| 174 | */
|
|---|
| 175 | const isEmptyObject = val => {
|
|---|
| 176 | // Early return for non-objects or Buffers to prevent RangeError
|
|---|
| 177 | if (!isObject(val) || isBuffer(val)) {
|
|---|
| 178 | return false;
|
|---|
| 179 | }
|
|---|
| 180 | try {
|
|---|
| 181 | return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
|
|---|
| 182 | } catch (e) {
|
|---|
| 183 | // Fallback for any other objects that might cause RangeError with Object.keys()
|
|---|
| 184 | return false;
|
|---|
| 185 | }
|
|---|
| 186 | };
|
|---|
| 187 |
|
|---|
| 188 | /**
|
|---|
| 189 | * Determine if a value is a Date
|
|---|
| 190 | *
|
|---|
| 191 | * @param {*} val The value to test
|
|---|
| 192 | *
|
|---|
| 193 | * @returns {boolean} True if value is a Date, otherwise false
|
|---|
| 194 | */
|
|---|
| 195 | const isDate = kindOfTest('Date');
|
|---|
| 196 |
|
|---|
| 197 | /**
|
|---|
| 198 | * Determine if a value is a File
|
|---|
| 199 | *
|
|---|
| 200 | * @param {*} val The value to test
|
|---|
| 201 | *
|
|---|
| 202 | * @returns {boolean} True if value is a File, otherwise false
|
|---|
| 203 | */
|
|---|
| 204 | const isFile = kindOfTest('File');
|
|---|
| 205 |
|
|---|
| 206 | /**
|
|---|
| 207 | * Determine if a value is a React Native Blob
|
|---|
| 208 | * React Native "blob": an object with a `uri` attribute. Optionally, it can
|
|---|
| 209 | * also have a `name` and `type` attribute to specify filename and content type
|
|---|
| 210 | *
|
|---|
| 211 | * @see https://github.com/facebook/react-native/blob/26684cf3adf4094eb6c405d345a75bf8c7c0bf88/Libraries/Network/FormData.js#L68-L71
|
|---|
| 212 | *
|
|---|
| 213 | * @param {*} value The value to test
|
|---|
| 214 | *
|
|---|
| 215 | * @returns {boolean} True if value is a React Native Blob, otherwise false
|
|---|
| 216 | */
|
|---|
| 217 | const isReactNativeBlob = value => {
|
|---|
| 218 | return !!(value && typeof value.uri !== 'undefined');
|
|---|
| 219 | };
|
|---|
| 220 |
|
|---|
| 221 | /**
|
|---|
| 222 | * Determine if environment is React Native
|
|---|
| 223 | * ReactNative `FormData` has a non-standard `getParts()` method
|
|---|
| 224 | *
|
|---|
| 225 | * @param {*} formData The formData to test
|
|---|
| 226 | *
|
|---|
| 227 | * @returns {boolean} True if environment is React Native, otherwise false
|
|---|
| 228 | */
|
|---|
| 229 | const isReactNative = formData => formData && typeof formData.getParts !== 'undefined';
|
|---|
| 230 |
|
|---|
| 231 | /**
|
|---|
| 232 | * Determine if a value is a Blob
|
|---|
| 233 | *
|
|---|
| 234 | * @param {*} val The value to test
|
|---|
| 235 | *
|
|---|
| 236 | * @returns {boolean} True if value is a Blob, otherwise false
|
|---|
| 237 | */
|
|---|
| 238 | const isBlob = kindOfTest('Blob');
|
|---|
| 239 |
|
|---|
| 240 | /**
|
|---|
| 241 | * Determine if a value is a FileList
|
|---|
| 242 | *
|
|---|
| 243 | * @param {*} val The value to test
|
|---|
| 244 | *
|
|---|
| 245 | * @returns {boolean} True if value is a FileList, otherwise false
|
|---|
| 246 | */
|
|---|
| 247 | const isFileList = kindOfTest('FileList');
|
|---|
| 248 |
|
|---|
| 249 | /**
|
|---|
| 250 | * Determine if a value is a Stream
|
|---|
| 251 | *
|
|---|
| 252 | * @param {*} val The value to test
|
|---|
| 253 | *
|
|---|
| 254 | * @returns {boolean} True if value is a Stream, otherwise false
|
|---|
| 255 | */
|
|---|
| 256 | const isStream = val => isObject(val) && isFunction$1(val.pipe);
|
|---|
| 257 |
|
|---|
| 258 | /**
|
|---|
| 259 | * Determine if a value is a FormData
|
|---|
| 260 | *
|
|---|
| 261 | * @param {*} thing The value to test
|
|---|
| 262 | *
|
|---|
| 263 | * @returns {boolean} True if value is an FormData, otherwise false
|
|---|
| 264 | */
|
|---|
| 265 | function getGlobal() {
|
|---|
| 266 | if (typeof globalThis !== 'undefined') return globalThis;
|
|---|
| 267 | if (typeof self !== 'undefined') return self;
|
|---|
| 268 | if (typeof window !== 'undefined') return window;
|
|---|
| 269 | if (typeof global !== 'undefined') return global;
|
|---|
| 270 | return {};
|
|---|
| 271 | }
|
|---|
| 272 | const G = getGlobal();
|
|---|
| 273 | const FormDataCtor = typeof G.FormData !== 'undefined' ? G.FormData : undefined;
|
|---|
| 274 | const isFormData = thing => {
|
|---|
| 275 | if (!thing) return false;
|
|---|
| 276 | if (FormDataCtor && thing instanceof FormDataCtor) return true;
|
|---|
| 277 | // Reject plain objects inheriting directly from Object.prototype so prototype-pollution gadgets can't spoof FormData.
|
|---|
| 278 | const proto = getPrototypeOf(thing);
|
|---|
| 279 | if (!proto || proto === Object.prototype) return false;
|
|---|
| 280 | if (!isFunction$1(thing.append)) return false;
|
|---|
| 281 | const kind = kindOf(thing);
|
|---|
| 282 | return kind === 'formdata' ||
|
|---|
| 283 | // detect form-data instance
|
|---|
| 284 | kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]';
|
|---|
| 285 | };
|
|---|
| 286 |
|
|---|
| 287 | /**
|
|---|
| 288 | * Determine if a value is a URLSearchParams object
|
|---|
| 289 | *
|
|---|
| 290 | * @param {*} val The value to test
|
|---|
| 291 | *
|
|---|
| 292 | * @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
|---|
| 293 | */
|
|---|
| 294 | const isURLSearchParams = kindOfTest('URLSearchParams');
|
|---|
| 295 | const [isReadableStream, isRequest, isResponse, isHeaders] = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest);
|
|---|
| 296 |
|
|---|
| 297 | /**
|
|---|
| 298 | * Trim excess whitespace off the beginning and end of a string
|
|---|
| 299 | *
|
|---|
| 300 | * @param {String} str The String to trim
|
|---|
| 301 | *
|
|---|
| 302 | * @returns {String} The String freed of excess whitespace
|
|---|
| 303 | */
|
|---|
| 304 | const trim = str => {
|
|---|
| 305 | return str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
|---|
| 306 | };
|
|---|
| 307 | /**
|
|---|
| 308 | * Iterate over an Array or an Object invoking a function for each item.
|
|---|
| 309 | *
|
|---|
| 310 | * If `obj` is an Array callback will be called passing
|
|---|
| 311 | * the value, index, and complete array for each item.
|
|---|
| 312 | *
|
|---|
| 313 | * If 'obj' is an Object callback will be called passing
|
|---|
| 314 | * the value, key, and complete object for each property.
|
|---|
| 315 | *
|
|---|
| 316 | * @param {Object|Array<unknown>} obj The object to iterate
|
|---|
| 317 | * @param {Function} fn The callback to invoke for each item
|
|---|
| 318 | *
|
|---|
| 319 | * @param {Object} [options]
|
|---|
| 320 | * @param {Boolean} [options.allOwnKeys = false]
|
|---|
| 321 | * @returns {any}
|
|---|
| 322 | */
|
|---|
| 323 | function forEach(obj, fn, {
|
|---|
| 324 | allOwnKeys = false
|
|---|
| 325 | } = {}) {
|
|---|
| 326 | // Don't bother if no value provided
|
|---|
| 327 | if (obj === null || typeof obj === 'undefined') {
|
|---|
| 328 | return;
|
|---|
| 329 | }
|
|---|
| 330 | let i;
|
|---|
| 331 | let l;
|
|---|
| 332 |
|
|---|
| 333 | // Force an array if not already something iterable
|
|---|
| 334 | if (typeof obj !== 'object') {
|
|---|
| 335 | /*eslint no-param-reassign:0*/
|
|---|
| 336 | obj = [obj];
|
|---|
| 337 | }
|
|---|
| 338 | if (isArray(obj)) {
|
|---|
| 339 | // Iterate over array values
|
|---|
| 340 | for (i = 0, l = obj.length; i < l; i++) {
|
|---|
| 341 | fn.call(null, obj[i], i, obj);
|
|---|
| 342 | }
|
|---|
| 343 | } else {
|
|---|
| 344 | // Buffer check
|
|---|
| 345 | if (isBuffer(obj)) {
|
|---|
| 346 | return;
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | // Iterate over object keys
|
|---|
| 350 | const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
|---|
| 351 | const len = keys.length;
|
|---|
| 352 | let key;
|
|---|
| 353 | for (i = 0; i < len; i++) {
|
|---|
| 354 | key = keys[i];
|
|---|
| 355 | fn.call(null, obj[key], key, obj);
|
|---|
| 356 | }
|
|---|
| 357 | }
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | /**
|
|---|
| 361 | * Finds a key in an object, case-insensitive, returning the actual key name.
|
|---|
| 362 | * Returns null if the object is a Buffer or if no match is found.
|
|---|
| 363 | *
|
|---|
| 364 | * @param {Object} obj - The object to search.
|
|---|
| 365 | * @param {string} key - The key to find (case-insensitive).
|
|---|
| 366 | * @returns {?string} The actual key name if found, otherwise null.
|
|---|
| 367 | */
|
|---|
| 368 | function findKey(obj, key) {
|
|---|
| 369 | if (isBuffer(obj)) {
|
|---|
| 370 | return null;
|
|---|
| 371 | }
|
|---|
| 372 | key = key.toLowerCase();
|
|---|
| 373 | const keys = Object.keys(obj);
|
|---|
| 374 | let i = keys.length;
|
|---|
| 375 | let _key;
|
|---|
| 376 | while (i-- > 0) {
|
|---|
| 377 | _key = keys[i];
|
|---|
| 378 | if (key === _key.toLowerCase()) {
|
|---|
| 379 | return _key;
|
|---|
| 380 | }
|
|---|
| 381 | }
|
|---|
| 382 | return null;
|
|---|
| 383 | }
|
|---|
| 384 | const _global = (() => {
|
|---|
| 385 | /*eslint no-undef:0*/
|
|---|
| 386 | if (typeof globalThis !== 'undefined') return globalThis;
|
|---|
| 387 | return typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : global;
|
|---|
| 388 | })();
|
|---|
| 389 | const isContextDefined = context => !isUndefined(context) && context !== _global;
|
|---|
| 390 |
|
|---|
| 391 | /**
|
|---|
| 392 | * Accepts varargs expecting each argument to be an object, then
|
|---|
| 393 | * immutably merges the properties of each object and returns result.
|
|---|
| 394 | *
|
|---|
| 395 | * When multiple objects contain the same key the later object in
|
|---|
| 396 | * the arguments list will take precedence.
|
|---|
| 397 | *
|
|---|
| 398 | * Example:
|
|---|
| 399 | *
|
|---|
| 400 | * ```js
|
|---|
| 401 | * const result = merge({foo: 123}, {foo: 456});
|
|---|
| 402 | * console.log(result.foo); // outputs 456
|
|---|
| 403 | * ```
|
|---|
| 404 | *
|
|---|
| 405 | * @param {Object} obj1 Object to merge
|
|---|
| 406 | *
|
|---|
| 407 | * @returns {Object} Result of all merge properties
|
|---|
| 408 | */
|
|---|
| 409 | function merge(...objs) {
|
|---|
| 410 | const {
|
|---|
| 411 | caseless,
|
|---|
| 412 | skipUndefined
|
|---|
| 413 | } = isContextDefined(this) && this || {};
|
|---|
| 414 | const result = {};
|
|---|
| 415 | const assignValue = (val, key) => {
|
|---|
| 416 | // Skip dangerous property names to prevent prototype pollution
|
|---|
| 417 | if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|---|
| 418 | return;
|
|---|
| 419 | }
|
|---|
| 420 | const targetKey = caseless && findKey(result, key) || key;
|
|---|
| 421 | // Read via own-prop only — a bare `result[targetKey]` walks the prototype
|
|---|
| 422 | // chain, so a polluted Object.prototype value could surface here and get
|
|---|
| 423 | // copied into the merged result.
|
|---|
| 424 | const existing = hasOwnProperty(result, targetKey) ? result[targetKey] : undefined;
|
|---|
| 425 | if (isPlainObject(existing) && isPlainObject(val)) {
|
|---|
| 426 | result[targetKey] = merge(existing, val);
|
|---|
| 427 | } else if (isPlainObject(val)) {
|
|---|
| 428 | result[targetKey] = merge({}, val);
|
|---|
| 429 | } else if (isArray(val)) {
|
|---|
| 430 | result[targetKey] = val.slice();
|
|---|
| 431 | } else if (!skipUndefined || !isUndefined(val)) {
|
|---|
| 432 | result[targetKey] = val;
|
|---|
| 433 | }
|
|---|
| 434 | };
|
|---|
| 435 | for (let i = 0, l = objs.length; i < l; i++) {
|
|---|
| 436 | objs[i] && forEach(objs[i], assignValue);
|
|---|
| 437 | }
|
|---|
| 438 | return result;
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | /**
|
|---|
| 442 | * Extends object a by mutably adding to it the properties of object b.
|
|---|
| 443 | *
|
|---|
| 444 | * @param {Object} a The object to be extended
|
|---|
| 445 | * @param {Object} b The object to copy properties from
|
|---|
| 446 | * @param {Object} thisArg The object to bind function to
|
|---|
| 447 | *
|
|---|
| 448 | * @param {Object} [options]
|
|---|
| 449 | * @param {Boolean} [options.allOwnKeys]
|
|---|
| 450 | * @returns {Object} The resulting value of object a
|
|---|
| 451 | */
|
|---|
| 452 | const extend = (a, b, thisArg, {
|
|---|
| 453 | allOwnKeys
|
|---|
| 454 | } = {}) => {
|
|---|
| 455 | forEach(b, (val, key) => {
|
|---|
| 456 | if (thisArg && isFunction$1(val)) {
|
|---|
| 457 | Object.defineProperty(a, key, {
|
|---|
| 458 | // Null-proto descriptor so a polluted Object.prototype.get cannot
|
|---|
| 459 | // hijack defineProperty's accessor-vs-data resolution.
|
|---|
| 460 | __proto__: null,
|
|---|
| 461 | value: bind(val, thisArg),
|
|---|
| 462 | writable: true,
|
|---|
| 463 | enumerable: true,
|
|---|
| 464 | configurable: true
|
|---|
| 465 | });
|
|---|
| 466 | } else {
|
|---|
| 467 | Object.defineProperty(a, key, {
|
|---|
| 468 | __proto__: null,
|
|---|
| 469 | value: val,
|
|---|
| 470 | writable: true,
|
|---|
| 471 | enumerable: true,
|
|---|
| 472 | configurable: true
|
|---|
| 473 | });
|
|---|
| 474 | }
|
|---|
| 475 | }, {
|
|---|
| 476 | allOwnKeys
|
|---|
| 477 | });
|
|---|
| 478 | return a;
|
|---|
| 479 | };
|
|---|
| 480 |
|
|---|
| 481 | /**
|
|---|
| 482 | * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
|---|
| 483 | *
|
|---|
| 484 | * @param {string} content with BOM
|
|---|
| 485 | *
|
|---|
| 486 | * @returns {string} content value without BOM
|
|---|
| 487 | */
|
|---|
| 488 | const stripBOM = content => {
|
|---|
| 489 | if (content.charCodeAt(0) === 0xfeff) {
|
|---|
| 490 | content = content.slice(1);
|
|---|
| 491 | }
|
|---|
| 492 | return content;
|
|---|
| 493 | };
|
|---|
| 494 |
|
|---|
| 495 | /**
|
|---|
| 496 | * Inherit the prototype methods from one constructor into another
|
|---|
| 497 | * @param {function} constructor
|
|---|
| 498 | * @param {function} superConstructor
|
|---|
| 499 | * @param {object} [props]
|
|---|
| 500 | * @param {object} [descriptors]
|
|---|
| 501 | *
|
|---|
| 502 | * @returns {void}
|
|---|
| 503 | */
|
|---|
| 504 | const inherits = (constructor, superConstructor, props, descriptors) => {
|
|---|
| 505 | constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
|---|
| 506 | Object.defineProperty(constructor.prototype, 'constructor', {
|
|---|
| 507 | __proto__: null,
|
|---|
| 508 | value: constructor,
|
|---|
| 509 | writable: true,
|
|---|
| 510 | enumerable: false,
|
|---|
| 511 | configurable: true
|
|---|
| 512 | });
|
|---|
| 513 | Object.defineProperty(constructor, 'super', {
|
|---|
| 514 | __proto__: null,
|
|---|
| 515 | value: superConstructor.prototype
|
|---|
| 516 | });
|
|---|
| 517 | props && Object.assign(constructor.prototype, props);
|
|---|
| 518 | };
|
|---|
| 519 |
|
|---|
| 520 | /**
|
|---|
| 521 | * Resolve object with deep prototype chain to a flat object
|
|---|
| 522 | * @param {Object} sourceObj source object
|
|---|
| 523 | * @param {Object} [destObj]
|
|---|
| 524 | * @param {Function|Boolean} [filter]
|
|---|
| 525 | * @param {Function} [propFilter]
|
|---|
| 526 | *
|
|---|
| 527 | * @returns {Object}
|
|---|
| 528 | */
|
|---|
| 529 | const toFlatObject = (sourceObj, destObj, filter, propFilter) => {
|
|---|
| 530 | let props;
|
|---|
| 531 | let i;
|
|---|
| 532 | let prop;
|
|---|
| 533 | const merged = {};
|
|---|
| 534 | destObj = destObj || {};
|
|---|
| 535 | // eslint-disable-next-line no-eq-null,eqeqeq
|
|---|
| 536 | if (sourceObj == null) return destObj;
|
|---|
| 537 | do {
|
|---|
| 538 | props = Object.getOwnPropertyNames(sourceObj);
|
|---|
| 539 | i = props.length;
|
|---|
| 540 | while (i-- > 0) {
|
|---|
| 541 | prop = props[i];
|
|---|
| 542 | if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
|
|---|
| 543 | destObj[prop] = sourceObj[prop];
|
|---|
| 544 | merged[prop] = true;
|
|---|
| 545 | }
|
|---|
| 546 | }
|
|---|
| 547 | sourceObj = filter !== false && getPrototypeOf(sourceObj);
|
|---|
| 548 | } while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
|---|
| 549 | return destObj;
|
|---|
| 550 | };
|
|---|
| 551 |
|
|---|
| 552 | /**
|
|---|
| 553 | * Determines whether a string ends with the characters of a specified string
|
|---|
| 554 | *
|
|---|
| 555 | * @param {String} str
|
|---|
| 556 | * @param {String} searchString
|
|---|
| 557 | * @param {Number} [position= 0]
|
|---|
| 558 | *
|
|---|
| 559 | * @returns {boolean}
|
|---|
| 560 | */
|
|---|
| 561 | const endsWith = (str, searchString, position) => {
|
|---|
| 562 | str = String(str);
|
|---|
| 563 | if (position === undefined || position > str.length) {
|
|---|
| 564 | position = str.length;
|
|---|
| 565 | }
|
|---|
| 566 | position -= searchString.length;
|
|---|
| 567 | const lastIndex = str.indexOf(searchString, position);
|
|---|
| 568 | return lastIndex !== -1 && lastIndex === position;
|
|---|
| 569 | };
|
|---|
| 570 |
|
|---|
| 571 | /**
|
|---|
| 572 | * Returns new array from array like object or null if failed
|
|---|
| 573 | *
|
|---|
| 574 | * @param {*} [thing]
|
|---|
| 575 | *
|
|---|
| 576 | * @returns {?Array}
|
|---|
| 577 | */
|
|---|
| 578 | const toArray = thing => {
|
|---|
| 579 | if (!thing) return null;
|
|---|
| 580 | if (isArray(thing)) return thing;
|
|---|
| 581 | let i = thing.length;
|
|---|
| 582 | if (!isNumber(i)) return null;
|
|---|
| 583 | const arr = new Array(i);
|
|---|
| 584 | while (i-- > 0) {
|
|---|
| 585 | arr[i] = thing[i];
|
|---|
| 586 | }
|
|---|
| 587 | return arr;
|
|---|
| 588 | };
|
|---|
| 589 |
|
|---|
| 590 | /**
|
|---|
| 591 | * Checking if the Uint8Array exists and if it does, it returns a function that checks if the
|
|---|
| 592 | * thing passed in is an instance of Uint8Array
|
|---|
| 593 | *
|
|---|
| 594 | * @param {TypedArray}
|
|---|
| 595 | *
|
|---|
| 596 | * @returns {Array}
|
|---|
| 597 | */
|
|---|
| 598 | // eslint-disable-next-line func-names
|
|---|
| 599 | const isTypedArray = (TypedArray => {
|
|---|
| 600 | // eslint-disable-next-line func-names
|
|---|
| 601 | return thing => {
|
|---|
| 602 | return TypedArray && thing instanceof TypedArray;
|
|---|
| 603 | };
|
|---|
| 604 | })(typeof Uint8Array !== 'undefined' && getPrototypeOf(Uint8Array));
|
|---|
| 605 |
|
|---|
| 606 | /**
|
|---|
| 607 | * For each entry in the object, call the function with the key and value.
|
|---|
| 608 | *
|
|---|
| 609 | * @param {Object<any, any>} obj - The object to iterate over.
|
|---|
| 610 | * @param {Function} fn - The function to call for each entry.
|
|---|
| 611 | *
|
|---|
| 612 | * @returns {void}
|
|---|
| 613 | */
|
|---|
| 614 | const forEachEntry = (obj, fn) => {
|
|---|
| 615 | const generator = obj && obj[iterator];
|
|---|
| 616 | const _iterator = generator.call(obj);
|
|---|
| 617 | let result;
|
|---|
| 618 | while ((result = _iterator.next()) && !result.done) {
|
|---|
| 619 | const pair = result.value;
|
|---|
| 620 | fn.call(obj, pair[0], pair[1]);
|
|---|
| 621 | }
|
|---|
| 622 | };
|
|---|
| 623 |
|
|---|
| 624 | /**
|
|---|
| 625 | * It takes a regular expression and a string, and returns an array of all the matches
|
|---|
| 626 | *
|
|---|
| 627 | * @param {string} regExp - The regular expression to match against.
|
|---|
| 628 | * @param {string} str - The string to search.
|
|---|
| 629 | *
|
|---|
| 630 | * @returns {Array<boolean>}
|
|---|
| 631 | */
|
|---|
| 632 | const matchAll = (regExp, str) => {
|
|---|
| 633 | let matches;
|
|---|
| 634 | const arr = [];
|
|---|
| 635 | while ((matches = regExp.exec(str)) !== null) {
|
|---|
| 636 | arr.push(matches);
|
|---|
| 637 | }
|
|---|
| 638 | return arr;
|
|---|
| 639 | };
|
|---|
| 640 |
|
|---|
| 641 | /* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */
|
|---|
| 642 | const isHTMLForm = kindOfTest('HTMLFormElement');
|
|---|
| 643 | const toCamelCase = str => {
|
|---|
| 644 | return str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function replacer(m, p1, p2) {
|
|---|
| 645 | return p1.toUpperCase() + p2;
|
|---|
| 646 | });
|
|---|
| 647 | };
|
|---|
| 648 |
|
|---|
| 649 | /* Creating a function that will check if an object has a property. */
|
|---|
| 650 | const hasOwnProperty = (({
|
|---|
| 651 | hasOwnProperty
|
|---|
| 652 | }) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
|
|---|
| 653 |
|
|---|
| 654 | /**
|
|---|
| 655 | * Determine if a value is a RegExp object
|
|---|
| 656 | *
|
|---|
| 657 | * @param {*} val The value to test
|
|---|
| 658 | *
|
|---|
| 659 | * @returns {boolean} True if value is a RegExp object, otherwise false
|
|---|
| 660 | */
|
|---|
| 661 | const isRegExp = kindOfTest('RegExp');
|
|---|
| 662 | const reduceDescriptors = (obj, reducer) => {
|
|---|
| 663 | const descriptors = Object.getOwnPropertyDescriptors(obj);
|
|---|
| 664 | const reducedDescriptors = {};
|
|---|
| 665 | forEach(descriptors, (descriptor, name) => {
|
|---|
| 666 | let ret;
|
|---|
| 667 | if ((ret = reducer(descriptor, name, obj)) !== false) {
|
|---|
| 668 | reducedDescriptors[name] = ret || descriptor;
|
|---|
| 669 | }
|
|---|
| 670 | });
|
|---|
| 671 | Object.defineProperties(obj, reducedDescriptors);
|
|---|
| 672 | };
|
|---|
| 673 |
|
|---|
| 674 | /**
|
|---|
| 675 | * Makes all methods read-only
|
|---|
| 676 | * @param {Object} obj
|
|---|
| 677 | */
|
|---|
| 678 |
|
|---|
| 679 | const freezeMethods = obj => {
|
|---|
| 680 | reduceDescriptors(obj, (descriptor, name) => {
|
|---|
| 681 | // skip restricted props in strict mode
|
|---|
| 682 | if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].includes(name)) {
|
|---|
| 683 | return false;
|
|---|
| 684 | }
|
|---|
| 685 | const value = obj[name];
|
|---|
| 686 | if (!isFunction$1(value)) return;
|
|---|
| 687 | descriptor.enumerable = false;
|
|---|
| 688 | if ('writable' in descriptor) {
|
|---|
| 689 | descriptor.writable = false;
|
|---|
| 690 | return;
|
|---|
| 691 | }
|
|---|
| 692 | if (!descriptor.set) {
|
|---|
| 693 | descriptor.set = () => {
|
|---|
| 694 | throw Error("Can not rewrite read-only method '" + name + "'");
|
|---|
| 695 | };
|
|---|
| 696 | }
|
|---|
| 697 | });
|
|---|
| 698 | };
|
|---|
| 699 |
|
|---|
| 700 | /**
|
|---|
| 701 | * Converts an array or a delimited string into an object set with values as keys and true as values.
|
|---|
| 702 | * Useful for fast membership checks.
|
|---|
| 703 | *
|
|---|
| 704 | * @param {Array|string} arrayOrString - The array or string to convert.
|
|---|
| 705 | * @param {string} delimiter - The delimiter to use if input is a string.
|
|---|
| 706 | * @returns {Object} An object with keys from the array or string, values set to true.
|
|---|
| 707 | */
|
|---|
| 708 | const toObjectSet = (arrayOrString, delimiter) => {
|
|---|
| 709 | const obj = {};
|
|---|
| 710 | const define = arr => {
|
|---|
| 711 | arr.forEach(value => {
|
|---|
| 712 | obj[value] = true;
|
|---|
| 713 | });
|
|---|
| 714 | };
|
|---|
| 715 | isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
|
|---|
| 716 | return obj;
|
|---|
| 717 | };
|
|---|
| 718 | const noop = () => {};
|
|---|
| 719 | const toFiniteNumber = (value, defaultValue) => {
|
|---|
| 720 | return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
|---|
| 721 | };
|
|---|
| 722 |
|
|---|
| 723 | /**
|
|---|
| 724 | * If the thing is a FormData object, return true, otherwise return false.
|
|---|
| 725 | *
|
|---|
| 726 | * @param {unknown} thing - The thing to check.
|
|---|
| 727 | *
|
|---|
| 728 | * @returns {boolean}
|
|---|
| 729 | */
|
|---|
| 730 | function isSpecCompliantForm(thing) {
|
|---|
| 731 | return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
|
|---|
| 732 | }
|
|---|
| 733 |
|
|---|
| 734 | /**
|
|---|
| 735 | * Recursively converts an object to a JSON-compatible object, handling circular references and Buffers.
|
|---|
| 736 | *
|
|---|
| 737 | * @param {Object} obj - The object to convert.
|
|---|
| 738 | * @returns {Object} The JSON-compatible object.
|
|---|
| 739 | */
|
|---|
| 740 | const toJSONObject = obj => {
|
|---|
| 741 | const visited = new WeakSet();
|
|---|
| 742 | const visit = source => {
|
|---|
| 743 | if (isObject(source)) {
|
|---|
| 744 | if (visited.has(source)) {
|
|---|
| 745 | return;
|
|---|
| 746 | }
|
|---|
| 747 |
|
|---|
| 748 | //Buffer check
|
|---|
| 749 | if (isBuffer(source)) {
|
|---|
| 750 | return source;
|
|---|
| 751 | }
|
|---|
| 752 | if (!('toJSON' in source)) {
|
|---|
| 753 | // add-on descent / delete-on-ascent: preserves path semantics, so DAG nodes serialise at every occurrence (see #7230).
|
|---|
| 754 | visited.add(source);
|
|---|
| 755 | const target = isArray(source) ? [] : {};
|
|---|
| 756 | forEach(source, (value, key) => {
|
|---|
| 757 | const reducedValue = visit(value);
|
|---|
| 758 | !isUndefined(reducedValue) && (target[key] = reducedValue);
|
|---|
| 759 | });
|
|---|
| 760 | visited.delete(source);
|
|---|
| 761 | return target;
|
|---|
| 762 | }
|
|---|
| 763 | }
|
|---|
| 764 | return source;
|
|---|
| 765 | };
|
|---|
| 766 | return visit(obj);
|
|---|
| 767 | };
|
|---|
| 768 |
|
|---|
| 769 | /**
|
|---|
| 770 | * Determines if a value is an async function.
|
|---|
| 771 | *
|
|---|
| 772 | * @param {*} thing - The value to test.
|
|---|
| 773 | * @returns {boolean} True if value is an async function, otherwise false.
|
|---|
| 774 | */
|
|---|
| 775 | const isAsyncFn = kindOfTest('AsyncFunction');
|
|---|
| 776 |
|
|---|
| 777 | /**
|
|---|
| 778 | * Determines if a value is thenable (has then and catch methods).
|
|---|
| 779 | *
|
|---|
| 780 | * @param {*} thing - The value to test.
|
|---|
| 781 | * @returns {boolean} True if value is thenable, otherwise false.
|
|---|
| 782 | */
|
|---|
| 783 | const isThenable = thing => thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
|
|---|
| 784 |
|
|---|
| 785 | // original code
|
|---|
| 786 | // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
|---|
| 787 |
|
|---|
| 788 | /**
|
|---|
| 789 | * Provides a cross-platform setImmediate implementation.
|
|---|
| 790 | * Uses native setImmediate if available, otherwise falls back to postMessage or setTimeout.
|
|---|
| 791 | *
|
|---|
| 792 | * @param {boolean} setImmediateSupported - Whether setImmediate is supported.
|
|---|
| 793 | * @param {boolean} postMessageSupported - Whether postMessage is supported.
|
|---|
| 794 | * @returns {Function} A function to schedule a callback asynchronously.
|
|---|
| 795 | */
|
|---|
| 796 | const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
|---|
| 797 | if (setImmediateSupported) {
|
|---|
| 798 | return setImmediate;
|
|---|
| 799 | }
|
|---|
| 800 | return postMessageSupported ? ((token, callbacks) => {
|
|---|
| 801 | _global.addEventListener('message', ({
|
|---|
| 802 | source,
|
|---|
| 803 | data
|
|---|
| 804 | }) => {
|
|---|
| 805 | if (source === _global && data === token) {
|
|---|
| 806 | callbacks.length && callbacks.shift()();
|
|---|
| 807 | }
|
|---|
| 808 | }, false);
|
|---|
| 809 | return cb => {
|
|---|
| 810 | callbacks.push(cb);
|
|---|
| 811 | _global.postMessage(token, '*');
|
|---|
| 812 | };
|
|---|
| 813 | })(`axios@${Math.random()}`, []) : cb => setTimeout(cb);
|
|---|
| 814 | })(typeof setImmediate === 'function', isFunction$1(_global.postMessage));
|
|---|
| 815 |
|
|---|
| 816 | /**
|
|---|
| 817 | * Schedules a microtask or asynchronous callback as soon as possible.
|
|---|
| 818 | * Uses queueMicrotask if available, otherwise falls back to process.nextTick or _setImmediate.
|
|---|
| 819 | *
|
|---|
| 820 | * @type {Function}
|
|---|
| 821 | */
|
|---|
| 822 | const asap = typeof queueMicrotask !== 'undefined' ? queueMicrotask.bind(_global) : typeof process !== 'undefined' && process.nextTick || _setImmediate;
|
|---|
| 823 |
|
|---|
| 824 | // *********************
|
|---|
| 825 |
|
|---|
| 826 | const isIterable = thing => thing != null && isFunction$1(thing[iterator]);
|
|---|
| 827 | var utils$1 = {
|
|---|
| 828 | isArray,
|
|---|
| 829 | isArrayBuffer,
|
|---|
| 830 | isBuffer,
|
|---|
| 831 | isFormData,
|
|---|
| 832 | isArrayBufferView,
|
|---|
| 833 | isString,
|
|---|
| 834 | isNumber,
|
|---|
| 835 | isBoolean,
|
|---|
| 836 | isObject,
|
|---|
| 837 | isPlainObject,
|
|---|
| 838 | isEmptyObject,
|
|---|
| 839 | isReadableStream,
|
|---|
| 840 | isRequest,
|
|---|
| 841 | isResponse,
|
|---|
| 842 | isHeaders,
|
|---|
| 843 | isUndefined,
|
|---|
| 844 | isDate,
|
|---|
| 845 | isFile,
|
|---|
| 846 | isReactNativeBlob,
|
|---|
| 847 | isReactNative,
|
|---|
| 848 | isBlob,
|
|---|
| 849 | isRegExp,
|
|---|
| 850 | isFunction: isFunction$1,
|
|---|
| 851 | isStream,
|
|---|
| 852 | isURLSearchParams,
|
|---|
| 853 | isTypedArray,
|
|---|
| 854 | isFileList,
|
|---|
| 855 | forEach,
|
|---|
| 856 | merge,
|
|---|
| 857 | extend,
|
|---|
| 858 | trim,
|
|---|
| 859 | stripBOM,
|
|---|
| 860 | inherits,
|
|---|
| 861 | toFlatObject,
|
|---|
| 862 | kindOf,
|
|---|
| 863 | kindOfTest,
|
|---|
| 864 | endsWith,
|
|---|
| 865 | toArray,
|
|---|
| 866 | forEachEntry,
|
|---|
| 867 | matchAll,
|
|---|
| 868 | isHTMLForm,
|
|---|
| 869 | hasOwnProperty,
|
|---|
| 870 | hasOwnProp: hasOwnProperty,
|
|---|
| 871 | // an alias to avoid ESLint no-prototype-builtins detection
|
|---|
| 872 | reduceDescriptors,
|
|---|
| 873 | freezeMethods,
|
|---|
| 874 | toObjectSet,
|
|---|
| 875 | toCamelCase,
|
|---|
| 876 | noop,
|
|---|
| 877 | toFiniteNumber,
|
|---|
| 878 | findKey,
|
|---|
| 879 | global: _global,
|
|---|
| 880 | isContextDefined,
|
|---|
| 881 | isSpecCompliantForm,
|
|---|
| 882 | toJSONObject,
|
|---|
| 883 | isAsyncFn,
|
|---|
| 884 | isThenable,
|
|---|
| 885 | setImmediate: _setImmediate,
|
|---|
| 886 | asap,
|
|---|
| 887 | isIterable
|
|---|
| 888 | };
|
|---|
| 889 |
|
|---|
| 890 | // RawAxiosHeaders whose duplicates are ignored by node
|
|---|
| 891 | // c.f. https://nodejs.org/api/http.html#http_message_headers
|
|---|
| 892 | const ignoreDuplicateOf = utils$1.toObjectSet(['age', 'authorization', 'content-length', 'content-type', 'etag', 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since', 'last-modified', 'location', 'max-forwards', 'proxy-authorization', 'referer', 'retry-after', 'user-agent']);
|
|---|
| 893 |
|
|---|
| 894 | /**
|
|---|
| 895 | * Parse headers into an object
|
|---|
| 896 | *
|
|---|
| 897 | * ```
|
|---|
| 898 | * Date: Wed, 27 Aug 2014 08:58:49 GMT
|
|---|
| 899 | * Content-Type: application/json
|
|---|
| 900 | * Connection: keep-alive
|
|---|
| 901 | * Transfer-Encoding: chunked
|
|---|
| 902 | * ```
|
|---|
| 903 | *
|
|---|
| 904 | * @param {String} rawHeaders Headers needing to be parsed
|
|---|
| 905 | *
|
|---|
| 906 | * @returns {Object} Headers parsed into an object
|
|---|
| 907 | */
|
|---|
| 908 | var parseHeaders = rawHeaders => {
|
|---|
| 909 | const parsed = {};
|
|---|
| 910 | let key;
|
|---|
| 911 | let val;
|
|---|
| 912 | let i;
|
|---|
| 913 | rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
|
|---|
| 914 | i = line.indexOf(':');
|
|---|
| 915 | key = line.substring(0, i).trim().toLowerCase();
|
|---|
| 916 | val = line.substring(i + 1).trim();
|
|---|
| 917 | if (!key || parsed[key] && ignoreDuplicateOf[key]) {
|
|---|
| 918 | return;
|
|---|
| 919 | }
|
|---|
| 920 | if (key === 'set-cookie') {
|
|---|
| 921 | if (parsed[key]) {
|
|---|
| 922 | parsed[key].push(val);
|
|---|
| 923 | } else {
|
|---|
| 924 | parsed[key] = [val];
|
|---|
| 925 | }
|
|---|
| 926 | } else {
|
|---|
| 927 | parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
|---|
| 928 | }
|
|---|
| 929 | });
|
|---|
| 930 | return parsed;
|
|---|
| 931 | };
|
|---|
| 932 |
|
|---|
| 933 | function trimSPorHTAB(str) {
|
|---|
| 934 | let start = 0;
|
|---|
| 935 | let end = str.length;
|
|---|
| 936 | while (start < end) {
|
|---|
| 937 | const code = str.charCodeAt(start);
|
|---|
| 938 | if (code !== 0x09 && code !== 0x20) {
|
|---|
| 939 | break;
|
|---|
| 940 | }
|
|---|
| 941 | start += 1;
|
|---|
| 942 | }
|
|---|
| 943 | while (end > start) {
|
|---|
| 944 | const code = str.charCodeAt(end - 1);
|
|---|
| 945 | if (code !== 0x09 && code !== 0x20) {
|
|---|
| 946 | break;
|
|---|
| 947 | }
|
|---|
| 948 | end -= 1;
|
|---|
| 949 | }
|
|---|
| 950 | return start === 0 && end === str.length ? str : str.slice(start, end);
|
|---|
| 951 | }
|
|---|
| 952 |
|
|---|
| 953 | // The control-code ranges are intentional: header sanitization strips C0/DEL bytes.
|
|---|
| 954 | // eslint-disable-next-line no-control-regex
|
|---|
| 955 | const INVALID_UNICODE_HEADER_VALUE_CHARS = new RegExp('[\\u0000-\\u0008\\u000a-\\u001f\\u007f]+', 'g');
|
|---|
| 956 | // eslint-disable-next-line no-control-regex
|
|---|
| 957 | const INVALID_BYTE_STRING_HEADER_VALUE_CHARS = new RegExp('[^\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+', 'g');
|
|---|
| 958 | function sanitizeValue(value, invalidChars) {
|
|---|
| 959 | if (utils$1.isArray(value)) {
|
|---|
| 960 | return value.map(item => sanitizeValue(item, invalidChars));
|
|---|
| 961 | }
|
|---|
| 962 | return trimSPorHTAB(String(value).replace(invalidChars, ''));
|
|---|
| 963 | }
|
|---|
| 964 | const sanitizeHeaderValue = value => sanitizeValue(value, INVALID_UNICODE_HEADER_VALUE_CHARS);
|
|---|
| 965 | const sanitizeByteStringHeaderValue = value => sanitizeValue(value, INVALID_BYTE_STRING_HEADER_VALUE_CHARS);
|
|---|
| 966 | function toByteStringHeaderObject(headers) {
|
|---|
| 967 | const byteStringHeaders = Object.create(null);
|
|---|
| 968 | utils$1.forEach(headers.toJSON(), (value, header) => {
|
|---|
| 969 | byteStringHeaders[header] = sanitizeByteStringHeaderValue(value);
|
|---|
| 970 | });
|
|---|
| 971 | return byteStringHeaders;
|
|---|
| 972 | }
|
|---|
| 973 |
|
|---|
| 974 | const $internals = Symbol('internals');
|
|---|
| 975 | function normalizeHeader(header) {
|
|---|
| 976 | return header && String(header).trim().toLowerCase();
|
|---|
| 977 | }
|
|---|
| 978 | function normalizeValue(value) {
|
|---|
| 979 | if (value === false || value == null) {
|
|---|
| 980 | return value;
|
|---|
| 981 | }
|
|---|
| 982 | return utils$1.isArray(value) ? value.map(normalizeValue) : sanitizeHeaderValue(String(value));
|
|---|
| 983 | }
|
|---|
| 984 | function parseTokens(str) {
|
|---|
| 985 | const tokens = Object.create(null);
|
|---|
| 986 | const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
|
|---|
| 987 | let match;
|
|---|
| 988 | while (match = tokensRE.exec(str)) {
|
|---|
| 989 | tokens[match[1]] = match[2];
|
|---|
| 990 | }
|
|---|
| 991 | return tokens;
|
|---|
| 992 | }
|
|---|
| 993 | const isValidHeaderName = str => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
|
|---|
| 994 | function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
|
|---|
| 995 | if (utils$1.isFunction(filter)) {
|
|---|
| 996 | return filter.call(this, value, header);
|
|---|
| 997 | }
|
|---|
| 998 | if (isHeaderNameFilter) {
|
|---|
| 999 | value = header;
|
|---|
| 1000 | }
|
|---|
| 1001 | if (!utils$1.isString(value)) return;
|
|---|
| 1002 | if (utils$1.isString(filter)) {
|
|---|
| 1003 | return value.indexOf(filter) !== -1;
|
|---|
| 1004 | }
|
|---|
| 1005 | if (utils$1.isRegExp(filter)) {
|
|---|
| 1006 | return filter.test(value);
|
|---|
| 1007 | }
|
|---|
| 1008 | }
|
|---|
| 1009 | function formatHeader(header) {
|
|---|
| 1010 | return header.trim().toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
|
|---|
| 1011 | return char.toUpperCase() + str;
|
|---|
| 1012 | });
|
|---|
| 1013 | }
|
|---|
| 1014 | function buildAccessors(obj, header) {
|
|---|
| 1015 | const accessorName = utils$1.toCamelCase(' ' + header);
|
|---|
| 1016 | ['get', 'set', 'has'].forEach(methodName => {
|
|---|
| 1017 | Object.defineProperty(obj, methodName + accessorName, {
|
|---|
| 1018 | // Null-proto descriptor so a polluted Object.prototype.get cannot turn
|
|---|
| 1019 | // this data descriptor into an accessor descriptor on the way in.
|
|---|
| 1020 | __proto__: null,
|
|---|
| 1021 | value: function (arg1, arg2, arg3) {
|
|---|
| 1022 | return this[methodName].call(this, header, arg1, arg2, arg3);
|
|---|
| 1023 | },
|
|---|
| 1024 | configurable: true
|
|---|
| 1025 | });
|
|---|
| 1026 | });
|
|---|
| 1027 | }
|
|---|
| 1028 | class AxiosHeaders {
|
|---|
| 1029 | constructor(headers) {
|
|---|
| 1030 | headers && this.set(headers);
|
|---|
| 1031 | }
|
|---|
| 1032 | set(header, valueOrRewrite, rewrite) {
|
|---|
| 1033 | const self = this;
|
|---|
| 1034 | function setHeader(_value, _header, _rewrite) {
|
|---|
| 1035 | const lHeader = normalizeHeader(_header);
|
|---|
| 1036 | if (!lHeader) {
|
|---|
| 1037 | throw new Error('header name must be a non-empty string');
|
|---|
| 1038 | }
|
|---|
| 1039 | const key = utils$1.findKey(self, lHeader);
|
|---|
| 1040 | if (!key || self[key] === undefined || _rewrite === true || _rewrite === undefined && self[key] !== false) {
|
|---|
| 1041 | self[key || _header] = normalizeValue(_value);
|
|---|
| 1042 | }
|
|---|
| 1043 | }
|
|---|
| 1044 | const setHeaders = (headers, _rewrite) => utils$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
|
|---|
| 1045 | if (utils$1.isPlainObject(header) || header instanceof this.constructor) {
|
|---|
| 1046 | setHeaders(header, valueOrRewrite);
|
|---|
| 1047 | } else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
|---|
| 1048 | setHeaders(parseHeaders(header), valueOrRewrite);
|
|---|
| 1049 | } else if (utils$1.isObject(header) && utils$1.isIterable(header)) {
|
|---|
| 1050 | let obj = {},
|
|---|
| 1051 | dest,
|
|---|
| 1052 | key;
|
|---|
| 1053 | for (const entry of header) {
|
|---|
| 1054 | if (!utils$1.isArray(entry)) {
|
|---|
| 1055 | throw TypeError('Object iterator must return a key-value pair');
|
|---|
| 1056 | }
|
|---|
| 1057 | obj[key = entry[0]] = (dest = obj[key]) ? utils$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]] : entry[1];
|
|---|
| 1058 | }
|
|---|
| 1059 | setHeaders(obj, valueOrRewrite);
|
|---|
| 1060 | } else {
|
|---|
| 1061 | header != null && setHeader(valueOrRewrite, header, rewrite);
|
|---|
| 1062 | }
|
|---|
| 1063 | return this;
|
|---|
| 1064 | }
|
|---|
| 1065 | get(header, parser) {
|
|---|
| 1066 | header = normalizeHeader(header);
|
|---|
| 1067 | if (header) {
|
|---|
| 1068 | const key = utils$1.findKey(this, header);
|
|---|
| 1069 | if (key) {
|
|---|
| 1070 | const value = this[key];
|
|---|
| 1071 | if (!parser) {
|
|---|
| 1072 | return value;
|
|---|
| 1073 | }
|
|---|
| 1074 | if (parser === true) {
|
|---|
| 1075 | return parseTokens(value);
|
|---|
| 1076 | }
|
|---|
| 1077 | if (utils$1.isFunction(parser)) {
|
|---|
| 1078 | return parser.call(this, value, key);
|
|---|
| 1079 | }
|
|---|
| 1080 | if (utils$1.isRegExp(parser)) {
|
|---|
| 1081 | return parser.exec(value);
|
|---|
| 1082 | }
|
|---|
| 1083 | throw new TypeError('parser must be boolean|regexp|function');
|
|---|
| 1084 | }
|
|---|
| 1085 | }
|
|---|
| 1086 | }
|
|---|
| 1087 | has(header, matcher) {
|
|---|
| 1088 | header = normalizeHeader(header);
|
|---|
| 1089 | if (header) {
|
|---|
| 1090 | const key = utils$1.findKey(this, header);
|
|---|
| 1091 | return !!(key && this[key] !== undefined && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
|
|---|
| 1092 | }
|
|---|
| 1093 | return false;
|
|---|
| 1094 | }
|
|---|
| 1095 | delete(header, matcher) {
|
|---|
| 1096 | const self = this;
|
|---|
| 1097 | let deleted = false;
|
|---|
| 1098 | function deleteHeader(_header) {
|
|---|
| 1099 | _header = normalizeHeader(_header);
|
|---|
| 1100 | if (_header) {
|
|---|
| 1101 | const key = utils$1.findKey(self, _header);
|
|---|
| 1102 | if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
|
|---|
| 1103 | delete self[key];
|
|---|
| 1104 | deleted = true;
|
|---|
| 1105 | }
|
|---|
| 1106 | }
|
|---|
| 1107 | }
|
|---|
| 1108 | if (utils$1.isArray(header)) {
|
|---|
| 1109 | header.forEach(deleteHeader);
|
|---|
| 1110 | } else {
|
|---|
| 1111 | deleteHeader(header);
|
|---|
| 1112 | }
|
|---|
| 1113 | return deleted;
|
|---|
| 1114 | }
|
|---|
| 1115 | clear(matcher) {
|
|---|
| 1116 | const keys = Object.keys(this);
|
|---|
| 1117 | let i = keys.length;
|
|---|
| 1118 | let deleted = false;
|
|---|
| 1119 | while (i--) {
|
|---|
| 1120 | const key = keys[i];
|
|---|
| 1121 | if (!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
|
|---|
| 1122 | delete this[key];
|
|---|
| 1123 | deleted = true;
|
|---|
| 1124 | }
|
|---|
| 1125 | }
|
|---|
| 1126 | return deleted;
|
|---|
| 1127 | }
|
|---|
| 1128 | normalize(format) {
|
|---|
| 1129 | const self = this;
|
|---|
| 1130 | const headers = {};
|
|---|
| 1131 | utils$1.forEach(this, (value, header) => {
|
|---|
| 1132 | const key = utils$1.findKey(headers, header);
|
|---|
| 1133 | if (key) {
|
|---|
| 1134 | self[key] = normalizeValue(value);
|
|---|
| 1135 | delete self[header];
|
|---|
| 1136 | return;
|
|---|
| 1137 | }
|
|---|
| 1138 | const normalized = format ? formatHeader(header) : String(header).trim();
|
|---|
| 1139 | if (normalized !== header) {
|
|---|
| 1140 | delete self[header];
|
|---|
| 1141 | }
|
|---|
| 1142 | self[normalized] = normalizeValue(value);
|
|---|
| 1143 | headers[normalized] = true;
|
|---|
| 1144 | });
|
|---|
| 1145 | return this;
|
|---|
| 1146 | }
|
|---|
| 1147 | concat(...targets) {
|
|---|
| 1148 | return this.constructor.concat(this, ...targets);
|
|---|
| 1149 | }
|
|---|
| 1150 | toJSON(asStrings) {
|
|---|
| 1151 | const obj = Object.create(null);
|
|---|
| 1152 | utils$1.forEach(this, (value, header) => {
|
|---|
| 1153 | value != null && value !== false && (obj[header] = asStrings && utils$1.isArray(value) ? value.join(', ') : value);
|
|---|
| 1154 | });
|
|---|
| 1155 | return obj;
|
|---|
| 1156 | }
|
|---|
| 1157 | [Symbol.iterator]() {
|
|---|
| 1158 | return Object.entries(this.toJSON())[Symbol.iterator]();
|
|---|
| 1159 | }
|
|---|
| 1160 | toString() {
|
|---|
| 1161 | return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
|
|---|
| 1162 | }
|
|---|
| 1163 | getSetCookie() {
|
|---|
| 1164 | return this.get('set-cookie') || [];
|
|---|
| 1165 | }
|
|---|
| 1166 | get [Symbol.toStringTag]() {
|
|---|
| 1167 | return 'AxiosHeaders';
|
|---|
| 1168 | }
|
|---|
| 1169 | static from(thing) {
|
|---|
| 1170 | return thing instanceof this ? thing : new this(thing);
|
|---|
| 1171 | }
|
|---|
| 1172 | static concat(first, ...targets) {
|
|---|
| 1173 | const computed = new this(first);
|
|---|
| 1174 | targets.forEach(target => computed.set(target));
|
|---|
| 1175 | return computed;
|
|---|
| 1176 | }
|
|---|
| 1177 | static accessor(header) {
|
|---|
| 1178 | const internals = this[$internals] = this[$internals] = {
|
|---|
| 1179 | accessors: {}
|
|---|
| 1180 | };
|
|---|
| 1181 | const accessors = internals.accessors;
|
|---|
| 1182 | const prototype = this.prototype;
|
|---|
| 1183 | function defineAccessor(_header) {
|
|---|
| 1184 | const lHeader = normalizeHeader(_header);
|
|---|
| 1185 | if (!accessors[lHeader]) {
|
|---|
| 1186 | buildAccessors(prototype, _header);
|
|---|
| 1187 | accessors[lHeader] = true;
|
|---|
| 1188 | }
|
|---|
| 1189 | }
|
|---|
| 1190 | utils$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
|---|
| 1191 | return this;
|
|---|
| 1192 | }
|
|---|
| 1193 | }
|
|---|
| 1194 | AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
|
|---|
| 1195 |
|
|---|
| 1196 | // reserved names hotfix
|
|---|
| 1197 | utils$1.reduceDescriptors(AxiosHeaders.prototype, ({
|
|---|
| 1198 | value
|
|---|
| 1199 | }, key) => {
|
|---|
| 1200 | let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
|
|---|
| 1201 | return {
|
|---|
| 1202 | get: () => value,
|
|---|
| 1203 | set(headerValue) {
|
|---|
| 1204 | this[mapped] = headerValue;
|
|---|
| 1205 | }
|
|---|
| 1206 | };
|
|---|
| 1207 | });
|
|---|
| 1208 | utils$1.freezeMethods(AxiosHeaders);
|
|---|
| 1209 |
|
|---|
| 1210 | const REDACTED = '[REDACTED ****]';
|
|---|
| 1211 | function hasOwnOrPrototypeToJSON(source) {
|
|---|
| 1212 | if (utils$1.hasOwnProp(source, 'toJSON')) {
|
|---|
| 1213 | return true;
|
|---|
| 1214 | }
|
|---|
| 1215 | let prototype = Object.getPrototypeOf(source);
|
|---|
| 1216 | while (prototype && prototype !== Object.prototype) {
|
|---|
| 1217 | if (utils$1.hasOwnProp(prototype, 'toJSON')) {
|
|---|
| 1218 | return true;
|
|---|
| 1219 | }
|
|---|
| 1220 | prototype = Object.getPrototypeOf(prototype);
|
|---|
| 1221 | }
|
|---|
| 1222 | return false;
|
|---|
| 1223 | }
|
|---|
| 1224 |
|
|---|
| 1225 | // Build a plain-object snapshot of `config` and replace the value of any key
|
|---|
| 1226 | // (case-insensitive) listed in `redactKeys` with REDACTED. Walks through arrays
|
|---|
| 1227 | // and AxiosHeaders, and short-circuits on circular references.
|
|---|
| 1228 | function redactConfig(config, redactKeys) {
|
|---|
| 1229 | const lowerKeys = new Set(redactKeys.map(k => String(k).toLowerCase()));
|
|---|
| 1230 | const seen = [];
|
|---|
| 1231 | const visit = source => {
|
|---|
| 1232 | if (source === null || typeof source !== 'object') return source;
|
|---|
| 1233 | if (utils$1.isBuffer(source)) return source;
|
|---|
| 1234 | if (seen.indexOf(source) !== -1) return undefined;
|
|---|
| 1235 | if (source instanceof AxiosHeaders) {
|
|---|
| 1236 | source = source.toJSON();
|
|---|
| 1237 | }
|
|---|
| 1238 | seen.push(source);
|
|---|
| 1239 | let result;
|
|---|
| 1240 | if (utils$1.isArray(source)) {
|
|---|
| 1241 | result = [];
|
|---|
| 1242 | source.forEach((v, i) => {
|
|---|
| 1243 | const reducedValue = visit(v);
|
|---|
| 1244 | if (!utils$1.isUndefined(reducedValue)) {
|
|---|
| 1245 | result[i] = reducedValue;
|
|---|
| 1246 | }
|
|---|
| 1247 | });
|
|---|
| 1248 | } else {
|
|---|
| 1249 | if (!utils$1.isPlainObject(source) && hasOwnOrPrototypeToJSON(source)) {
|
|---|
| 1250 | seen.pop();
|
|---|
| 1251 | return source;
|
|---|
| 1252 | }
|
|---|
| 1253 | result = Object.create(null);
|
|---|
| 1254 | for (const [key, value] of Object.entries(source)) {
|
|---|
| 1255 | const reducedValue = lowerKeys.has(key.toLowerCase()) ? REDACTED : visit(value);
|
|---|
| 1256 | if (!utils$1.isUndefined(reducedValue)) {
|
|---|
| 1257 | result[key] = reducedValue;
|
|---|
| 1258 | }
|
|---|
| 1259 | }
|
|---|
| 1260 | }
|
|---|
| 1261 | seen.pop();
|
|---|
| 1262 | return result;
|
|---|
| 1263 | };
|
|---|
| 1264 | return visit(config);
|
|---|
| 1265 | }
|
|---|
| 1266 | class AxiosError extends Error {
|
|---|
| 1267 | static from(error, code, config, request, response, customProps) {
|
|---|
| 1268 | const axiosError = new AxiosError(error.message, code || error.code, config, request, response);
|
|---|
| 1269 | axiosError.cause = error;
|
|---|
| 1270 | axiosError.name = error.name;
|
|---|
| 1271 |
|
|---|
| 1272 | // Preserve status from the original error if not already set from response
|
|---|
| 1273 | if (error.status != null && axiosError.status == null) {
|
|---|
| 1274 | axiosError.status = error.status;
|
|---|
| 1275 | }
|
|---|
| 1276 | customProps && Object.assign(axiosError, customProps);
|
|---|
| 1277 | return axiosError;
|
|---|
| 1278 | }
|
|---|
| 1279 |
|
|---|
| 1280 | /**
|
|---|
| 1281 | * Create an Error with the specified message, config, error code, request and response.
|
|---|
| 1282 | *
|
|---|
| 1283 | * @param {string} message The error message.
|
|---|
| 1284 | * @param {string} [code] The error code (for example, 'ECONNABORTED').
|
|---|
| 1285 | * @param {Object} [config] The config.
|
|---|
| 1286 | * @param {Object} [request] The request.
|
|---|
| 1287 | * @param {Object} [response] The response.
|
|---|
| 1288 | *
|
|---|
| 1289 | * @returns {Error} The created error.
|
|---|
| 1290 | */
|
|---|
| 1291 | constructor(message, code, config, request, response) {
|
|---|
| 1292 | super(message);
|
|---|
| 1293 |
|
|---|
| 1294 | // Make message enumerable to maintain backward compatibility
|
|---|
| 1295 | // The native Error constructor sets message as non-enumerable,
|
|---|
| 1296 | // but axios < v1.13.3 had it as enumerable
|
|---|
| 1297 | Object.defineProperty(this, 'message', {
|
|---|
| 1298 | // Null-proto descriptor so a polluted Object.prototype.get cannot turn
|
|---|
| 1299 | // this data descriptor into an accessor descriptor on the way in.
|
|---|
| 1300 | __proto__: null,
|
|---|
| 1301 | value: message,
|
|---|
| 1302 | enumerable: true,
|
|---|
| 1303 | writable: true,
|
|---|
| 1304 | configurable: true
|
|---|
| 1305 | });
|
|---|
| 1306 | this.name = 'AxiosError';
|
|---|
| 1307 | this.isAxiosError = true;
|
|---|
| 1308 | code && (this.code = code);
|
|---|
| 1309 | config && (this.config = config);
|
|---|
| 1310 | request && (this.request = request);
|
|---|
| 1311 | if (response) {
|
|---|
| 1312 | this.response = response;
|
|---|
| 1313 | this.status = response.status;
|
|---|
| 1314 | }
|
|---|
| 1315 | }
|
|---|
| 1316 | toJSON() {
|
|---|
| 1317 | // Opt-in redaction: when the request config carries a `redact` array, the
|
|---|
| 1318 | // value of any matching key (case-insensitive, at any depth) is replaced
|
|---|
| 1319 | // with REDACTED in the serialized snapshot. Undefined or empty leaves the
|
|---|
| 1320 | // existing serialization behavior unchanged.
|
|---|
| 1321 | const config = this.config;
|
|---|
| 1322 | const redactKeys = config && utils$1.hasOwnProp(config, 'redact') ? config.redact : undefined;
|
|---|
| 1323 | const serializedConfig = utils$1.isArray(redactKeys) && redactKeys.length > 0 ? redactConfig(config, redactKeys) : utils$1.toJSONObject(config);
|
|---|
| 1324 | return {
|
|---|
| 1325 | // Standard
|
|---|
| 1326 | message: this.message,
|
|---|
| 1327 | name: this.name,
|
|---|
| 1328 | // Microsoft
|
|---|
| 1329 | description: this.description,
|
|---|
| 1330 | number: this.number,
|
|---|
| 1331 | // Mozilla
|
|---|
| 1332 | fileName: this.fileName,
|
|---|
| 1333 | lineNumber: this.lineNumber,
|
|---|
| 1334 | columnNumber: this.columnNumber,
|
|---|
| 1335 | stack: this.stack,
|
|---|
| 1336 | // Axios
|
|---|
| 1337 | config: serializedConfig,
|
|---|
| 1338 | code: this.code,
|
|---|
| 1339 | status: this.status
|
|---|
| 1340 | };
|
|---|
| 1341 | }
|
|---|
| 1342 | }
|
|---|
| 1343 |
|
|---|
| 1344 | // This can be changed to static properties as soon as the parser options in .eslint.cjs are updated.
|
|---|
| 1345 | AxiosError.ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE';
|
|---|
| 1346 | AxiosError.ERR_BAD_OPTION = 'ERR_BAD_OPTION';
|
|---|
| 1347 | AxiosError.ECONNABORTED = 'ECONNABORTED';
|
|---|
| 1348 | AxiosError.ETIMEDOUT = 'ETIMEDOUT';
|
|---|
| 1349 | AxiosError.ECONNREFUSED = 'ECONNREFUSED';
|
|---|
| 1350 | AxiosError.ERR_NETWORK = 'ERR_NETWORK';
|
|---|
| 1351 | AxiosError.ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS';
|
|---|
| 1352 | AxiosError.ERR_DEPRECATED = 'ERR_DEPRECATED';
|
|---|
| 1353 | AxiosError.ERR_BAD_RESPONSE = 'ERR_BAD_RESPONSE';
|
|---|
| 1354 | AxiosError.ERR_BAD_REQUEST = 'ERR_BAD_REQUEST';
|
|---|
| 1355 | AxiosError.ERR_CANCELED = 'ERR_CANCELED';
|
|---|
| 1356 | AxiosError.ERR_NOT_SUPPORT = 'ERR_NOT_SUPPORT';
|
|---|
| 1357 | AxiosError.ERR_INVALID_URL = 'ERR_INVALID_URL';
|
|---|
| 1358 | AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED = 'ERR_FORM_DATA_DEPTH_EXCEEDED';
|
|---|
| 1359 |
|
|---|
| 1360 | /**
|
|---|
| 1361 | * Determines if the given thing is a array or js object.
|
|---|
| 1362 | *
|
|---|
| 1363 | * @param {string} thing - The object or array to be visited.
|
|---|
| 1364 | *
|
|---|
| 1365 | * @returns {boolean}
|
|---|
| 1366 | */
|
|---|
| 1367 | function isVisitable(thing) {
|
|---|
| 1368 | return utils$1.isPlainObject(thing) || utils$1.isArray(thing);
|
|---|
| 1369 | }
|
|---|
| 1370 |
|
|---|
| 1371 | /**
|
|---|
| 1372 | * It removes the brackets from the end of a string
|
|---|
| 1373 | *
|
|---|
| 1374 | * @param {string} key - The key of the parameter.
|
|---|
| 1375 | *
|
|---|
| 1376 | * @returns {string} the key without the brackets.
|
|---|
| 1377 | */
|
|---|
| 1378 | function removeBrackets(key) {
|
|---|
| 1379 | return utils$1.endsWith(key, '[]') ? key.slice(0, -2) : key;
|
|---|
| 1380 | }
|
|---|
| 1381 |
|
|---|
| 1382 | /**
|
|---|
| 1383 | * It takes a path, a key, and a boolean, and returns a string
|
|---|
| 1384 | *
|
|---|
| 1385 | * @param {string} path - The path to the current key.
|
|---|
| 1386 | * @param {string} key - The key of the current object being iterated over.
|
|---|
| 1387 | * @param {string} dots - If true, the key will be rendered with dots instead of brackets.
|
|---|
| 1388 | *
|
|---|
| 1389 | * @returns {string} The path to the current key.
|
|---|
| 1390 | */
|
|---|
| 1391 | function renderKey(path, key, dots) {
|
|---|
| 1392 | if (!path) return key;
|
|---|
| 1393 | return path.concat(key).map(function each(token, i) {
|
|---|
| 1394 | // eslint-disable-next-line no-param-reassign
|
|---|
| 1395 | token = removeBrackets(token);
|
|---|
| 1396 | return !dots && i ? '[' + token + ']' : token;
|
|---|
| 1397 | }).join(dots ? '.' : '');
|
|---|
| 1398 | }
|
|---|
| 1399 |
|
|---|
| 1400 | /**
|
|---|
| 1401 | * If the array is an array and none of its elements are visitable, then it's a flat array.
|
|---|
| 1402 | *
|
|---|
| 1403 | * @param {Array<any>} arr - The array to check
|
|---|
| 1404 | *
|
|---|
| 1405 | * @returns {boolean}
|
|---|
| 1406 | */
|
|---|
| 1407 | function isFlatArray(arr) {
|
|---|
| 1408 | return utils$1.isArray(arr) && !arr.some(isVisitable);
|
|---|
| 1409 | }
|
|---|
| 1410 | const predicates = utils$1.toFlatObject(utils$1, {}, null, function filter(prop) {
|
|---|
| 1411 | return /^is[A-Z]/.test(prop);
|
|---|
| 1412 | });
|
|---|
| 1413 |
|
|---|
| 1414 | /**
|
|---|
| 1415 | * Convert a data object to FormData
|
|---|
| 1416 | *
|
|---|
| 1417 | * @param {Object} obj
|
|---|
| 1418 | * @param {?Object} [formData]
|
|---|
| 1419 | * @param {?Object} [options]
|
|---|
| 1420 | * @param {Function} [options.visitor]
|
|---|
| 1421 | * @param {Boolean} [options.metaTokens = true]
|
|---|
| 1422 | * @param {Boolean} [options.dots = false]
|
|---|
| 1423 | * @param {?Boolean} [options.indexes = false]
|
|---|
| 1424 | *
|
|---|
| 1425 | * @returns {Object}
|
|---|
| 1426 | **/
|
|---|
| 1427 |
|
|---|
| 1428 | /**
|
|---|
| 1429 | * It converts an object into a FormData object
|
|---|
| 1430 | *
|
|---|
| 1431 | * @param {Object<any, any>} obj - The object to convert to form data.
|
|---|
| 1432 | * @param {string} formData - The FormData object to append to.
|
|---|
| 1433 | * @param {Object<string, any>} options
|
|---|
| 1434 | *
|
|---|
| 1435 | * @returns
|
|---|
| 1436 | */
|
|---|
| 1437 | function toFormData(obj, formData, options) {
|
|---|
| 1438 | if (!utils$1.isObject(obj)) {
|
|---|
| 1439 | throw new TypeError('target must be an object');
|
|---|
| 1440 | }
|
|---|
| 1441 |
|
|---|
| 1442 | // eslint-disable-next-line no-param-reassign
|
|---|
| 1443 | formData = formData || new (FormData$1 || FormData)();
|
|---|
| 1444 |
|
|---|
| 1445 | // eslint-disable-next-line no-param-reassign
|
|---|
| 1446 | options = utils$1.toFlatObject(options, {
|
|---|
| 1447 | metaTokens: true,
|
|---|
| 1448 | dots: false,
|
|---|
| 1449 | indexes: false
|
|---|
| 1450 | }, false, function defined(option, source) {
|
|---|
| 1451 | // eslint-disable-next-line no-eq-null,eqeqeq
|
|---|
| 1452 | return !utils$1.isUndefined(source[option]);
|
|---|
| 1453 | });
|
|---|
| 1454 | const metaTokens = options.metaTokens;
|
|---|
| 1455 | // eslint-disable-next-line no-use-before-define
|
|---|
| 1456 | const visitor = options.visitor || defaultVisitor;
|
|---|
| 1457 | const dots = options.dots;
|
|---|
| 1458 | const indexes = options.indexes;
|
|---|
| 1459 | const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
|
|---|
| 1460 | const maxDepth = options.maxDepth === undefined ? 100 : options.maxDepth;
|
|---|
| 1461 | const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
|
|---|
| 1462 | if (!utils$1.isFunction(visitor)) {
|
|---|
| 1463 | throw new TypeError('visitor must be a function');
|
|---|
| 1464 | }
|
|---|
| 1465 | function convertValue(value) {
|
|---|
| 1466 | if (value === null) return '';
|
|---|
| 1467 | if (utils$1.isDate(value)) {
|
|---|
| 1468 | return value.toISOString();
|
|---|
| 1469 | }
|
|---|
| 1470 | if (utils$1.isBoolean(value)) {
|
|---|
| 1471 | return value.toString();
|
|---|
| 1472 | }
|
|---|
| 1473 | if (!useBlob && utils$1.isBlob(value)) {
|
|---|
| 1474 | throw new AxiosError('Blob is not supported. Use a Buffer instead.');
|
|---|
| 1475 | }
|
|---|
| 1476 | if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
|
|---|
| 1477 | return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
|
|---|
| 1478 | }
|
|---|
| 1479 | return value;
|
|---|
| 1480 | }
|
|---|
| 1481 |
|
|---|
| 1482 | /**
|
|---|
| 1483 | * Default visitor.
|
|---|
| 1484 | *
|
|---|
| 1485 | * @param {*} value
|
|---|
| 1486 | * @param {String|Number} key
|
|---|
| 1487 | * @param {Array<String|Number>} path
|
|---|
| 1488 | * @this {FormData}
|
|---|
| 1489 | *
|
|---|
| 1490 | * @returns {boolean} return true to visit the each prop of the value recursively
|
|---|
| 1491 | */
|
|---|
| 1492 | function defaultVisitor(value, key, path) {
|
|---|
| 1493 | let arr = value;
|
|---|
| 1494 | if (utils$1.isReactNative(formData) && utils$1.isReactNativeBlob(value)) {
|
|---|
| 1495 | formData.append(renderKey(path, key, dots), convertValue(value));
|
|---|
| 1496 | return false;
|
|---|
| 1497 | }
|
|---|
| 1498 | if (value && !path && typeof value === 'object') {
|
|---|
| 1499 | if (utils$1.endsWith(key, '{}')) {
|
|---|
| 1500 | // eslint-disable-next-line no-param-reassign
|
|---|
| 1501 | key = metaTokens ? key : key.slice(0, -2);
|
|---|
| 1502 | // eslint-disable-next-line no-param-reassign
|
|---|
| 1503 | value = JSON.stringify(value);
|
|---|
| 1504 | } else if (utils$1.isArray(value) && isFlatArray(value) || (utils$1.isFileList(value) || utils$1.endsWith(key, '[]')) && (arr = utils$1.toArray(value))) {
|
|---|
| 1505 | // eslint-disable-next-line no-param-reassign
|
|---|
| 1506 | key = removeBrackets(key);
|
|---|
| 1507 | arr.forEach(function each(el, index) {
|
|---|
| 1508 | !(utils$1.isUndefined(el) || el === null) && formData.append(
|
|---|
| 1509 | // eslint-disable-next-line no-nested-ternary
|
|---|
| 1510 | indexes === true ? renderKey([key], index, dots) : indexes === null ? key : key + '[]', convertValue(el));
|
|---|
| 1511 | });
|
|---|
| 1512 | return false;
|
|---|
| 1513 | }
|
|---|
| 1514 | }
|
|---|
| 1515 | if (isVisitable(value)) {
|
|---|
| 1516 | return true;
|
|---|
| 1517 | }
|
|---|
| 1518 | formData.append(renderKey(path, key, dots), convertValue(value));
|
|---|
| 1519 | return false;
|
|---|
| 1520 | }
|
|---|
| 1521 | const stack = [];
|
|---|
| 1522 | const exposedHelpers = Object.assign(predicates, {
|
|---|
| 1523 | defaultVisitor,
|
|---|
| 1524 | convertValue,
|
|---|
| 1525 | isVisitable
|
|---|
| 1526 | });
|
|---|
| 1527 | function build(value, path, depth = 0) {
|
|---|
| 1528 | if (utils$1.isUndefined(value)) return;
|
|---|
| 1529 | if (depth > maxDepth) {
|
|---|
| 1530 | throw new AxiosError('Object is too deeply nested (' + depth + ' levels). Max depth: ' + maxDepth, AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED);
|
|---|
| 1531 | }
|
|---|
| 1532 | if (stack.indexOf(value) !== -1) {
|
|---|
| 1533 | throw Error('Circular reference detected in ' + path.join('.'));
|
|---|
| 1534 | }
|
|---|
| 1535 | stack.push(value);
|
|---|
| 1536 | utils$1.forEach(value, function each(el, key) {
|
|---|
| 1537 | const result = !(utils$1.isUndefined(el) || el === null) && visitor.call(formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers);
|
|---|
| 1538 | if (result === true) {
|
|---|
| 1539 | build(el, path ? path.concat(key) : [key], depth + 1);
|
|---|
| 1540 | }
|
|---|
| 1541 | });
|
|---|
| 1542 | stack.pop();
|
|---|
| 1543 | }
|
|---|
| 1544 | if (!utils$1.isObject(obj)) {
|
|---|
| 1545 | throw new TypeError('data must be an object');
|
|---|
| 1546 | }
|
|---|
| 1547 | build(obj);
|
|---|
| 1548 | return formData;
|
|---|
| 1549 | }
|
|---|
| 1550 |
|
|---|
| 1551 | /**
|
|---|
| 1552 | * It encodes a string by replacing all characters that are not in the unreserved set with
|
|---|
| 1553 | * their percent-encoded equivalents
|
|---|
| 1554 | *
|
|---|
| 1555 | * @param {string} str - The string to encode.
|
|---|
| 1556 | *
|
|---|
| 1557 | * @returns {string} The encoded string.
|
|---|
| 1558 | */
|
|---|
| 1559 | function encode$1(str) {
|
|---|
| 1560 | const charMap = {
|
|---|
| 1561 | '!': '%21',
|
|---|
| 1562 | "'": '%27',
|
|---|
| 1563 | '(': '%28',
|
|---|
| 1564 | ')': '%29',
|
|---|
| 1565 | '~': '%7E',
|
|---|
| 1566 | '%20': '+'
|
|---|
| 1567 | };
|
|---|
| 1568 | return encodeURIComponent(str).replace(/[!'()~]|%20/g, function replacer(match) {
|
|---|
| 1569 | return charMap[match];
|
|---|
| 1570 | });
|
|---|
| 1571 | }
|
|---|
| 1572 |
|
|---|
| 1573 | /**
|
|---|
| 1574 | * It takes a params object and converts it to a FormData object
|
|---|
| 1575 | *
|
|---|
| 1576 | * @param {Object<string, any>} params - The parameters to be converted to a FormData object.
|
|---|
| 1577 | * @param {Object<string, any>} options - The options object passed to the Axios constructor.
|
|---|
| 1578 | *
|
|---|
| 1579 | * @returns {void}
|
|---|
| 1580 | */
|
|---|
| 1581 | function AxiosURLSearchParams(params, options) {
|
|---|
| 1582 | this._pairs = [];
|
|---|
| 1583 | params && toFormData(params, this, options);
|
|---|
| 1584 | }
|
|---|
| 1585 | const prototype = AxiosURLSearchParams.prototype;
|
|---|
| 1586 | prototype.append = function append(name, value) {
|
|---|
| 1587 | this._pairs.push([name, value]);
|
|---|
| 1588 | };
|
|---|
| 1589 | prototype.toString = function toString(encoder) {
|
|---|
| 1590 | const _encode = encoder ? function (value) {
|
|---|
| 1591 | return encoder.call(this, value, encode$1);
|
|---|
| 1592 | } : encode$1;
|
|---|
| 1593 | return this._pairs.map(function each(pair) {
|
|---|
| 1594 | return _encode(pair[0]) + '=' + _encode(pair[1]);
|
|---|
| 1595 | }, '').join('&');
|
|---|
| 1596 | };
|
|---|
| 1597 |
|
|---|
| 1598 | /**
|
|---|
| 1599 | * It replaces URL-encoded forms of `:`, `$`, `,`, and spaces with
|
|---|
| 1600 | * their plain counterparts (`:`, `$`, `,`, `+`).
|
|---|
| 1601 | *
|
|---|
| 1602 | * @param {string} val The value to be encoded.
|
|---|
| 1603 | *
|
|---|
| 1604 | * @returns {string} The encoded value.
|
|---|
| 1605 | */
|
|---|
| 1606 | function encode(val) {
|
|---|
| 1607 | return encodeURIComponent(val).replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, '+');
|
|---|
| 1608 | }
|
|---|
| 1609 |
|
|---|
| 1610 | /**
|
|---|
| 1611 | * Build a URL by appending params to the end
|
|---|
| 1612 | *
|
|---|
| 1613 | * @param {string} url The base of the url (e.g., http://www.google.com)
|
|---|
| 1614 | * @param {object} [params] The params to be appended
|
|---|
| 1615 | * @param {?(object|Function)} options
|
|---|
| 1616 | *
|
|---|
| 1617 | * @returns {string} The formatted url
|
|---|
| 1618 | */
|
|---|
| 1619 | function buildURL(url, params, options) {
|
|---|
| 1620 | if (!params) {
|
|---|
| 1621 | return url;
|
|---|
| 1622 | }
|
|---|
| 1623 | const _encode = options && options.encode || encode;
|
|---|
| 1624 | const _options = utils$1.isFunction(options) ? {
|
|---|
| 1625 | serialize: options
|
|---|
| 1626 | } : options;
|
|---|
| 1627 | const serializeFn = _options && _options.serialize;
|
|---|
| 1628 | let serializedParams;
|
|---|
| 1629 | if (serializeFn) {
|
|---|
| 1630 | serializedParams = serializeFn(params, _options);
|
|---|
| 1631 | } else {
|
|---|
| 1632 | serializedParams = utils$1.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params, _options).toString(_encode);
|
|---|
| 1633 | }
|
|---|
| 1634 | if (serializedParams) {
|
|---|
| 1635 | const hashmarkIndex = url.indexOf('#');
|
|---|
| 1636 | if (hashmarkIndex !== -1) {
|
|---|
| 1637 | url = url.slice(0, hashmarkIndex);
|
|---|
| 1638 | }
|
|---|
| 1639 | url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
|---|
| 1640 | }
|
|---|
| 1641 | return url;
|
|---|
| 1642 | }
|
|---|
| 1643 |
|
|---|
| 1644 | class InterceptorManager {
|
|---|
| 1645 | constructor() {
|
|---|
| 1646 | this.handlers = [];
|
|---|
| 1647 | }
|
|---|
| 1648 |
|
|---|
| 1649 | /**
|
|---|
| 1650 | * Add a new interceptor to the stack
|
|---|
| 1651 | *
|
|---|
| 1652 | * @param {Function} fulfilled The function to handle `then` for a `Promise`
|
|---|
| 1653 | * @param {Function} rejected The function to handle `reject` for a `Promise`
|
|---|
| 1654 | * @param {Object} options The options for the interceptor, synchronous and runWhen
|
|---|
| 1655 | *
|
|---|
| 1656 | * @return {Number} An ID used to remove interceptor later
|
|---|
| 1657 | */
|
|---|
| 1658 | use(fulfilled, rejected, options) {
|
|---|
| 1659 | this.handlers.push({
|
|---|
| 1660 | fulfilled,
|
|---|
| 1661 | rejected,
|
|---|
| 1662 | synchronous: options ? options.synchronous : false,
|
|---|
| 1663 | runWhen: options ? options.runWhen : null
|
|---|
| 1664 | });
|
|---|
| 1665 | return this.handlers.length - 1;
|
|---|
| 1666 | }
|
|---|
| 1667 |
|
|---|
| 1668 | /**
|
|---|
| 1669 | * Remove an interceptor from the stack
|
|---|
| 1670 | *
|
|---|
| 1671 | * @param {Number} id The ID that was returned by `use`
|
|---|
| 1672 | *
|
|---|
| 1673 | * @returns {void}
|
|---|
| 1674 | */
|
|---|
| 1675 | eject(id) {
|
|---|
| 1676 | if (this.handlers[id]) {
|
|---|
| 1677 | this.handlers[id] = null;
|
|---|
| 1678 | }
|
|---|
| 1679 | }
|
|---|
| 1680 |
|
|---|
| 1681 | /**
|
|---|
| 1682 | * Clear all interceptors from the stack
|
|---|
| 1683 | *
|
|---|
| 1684 | * @returns {void}
|
|---|
| 1685 | */
|
|---|
| 1686 | clear() {
|
|---|
| 1687 | if (this.handlers) {
|
|---|
| 1688 | this.handlers = [];
|
|---|
| 1689 | }
|
|---|
| 1690 | }
|
|---|
| 1691 |
|
|---|
| 1692 | /**
|
|---|
| 1693 | * Iterate over all the registered interceptors
|
|---|
| 1694 | *
|
|---|
| 1695 | * This method is particularly useful for skipping over any
|
|---|
| 1696 | * interceptors that may have become `null` calling `eject`.
|
|---|
| 1697 | *
|
|---|
| 1698 | * @param {Function} fn The function to call for each interceptor
|
|---|
| 1699 | *
|
|---|
| 1700 | * @returns {void}
|
|---|
| 1701 | */
|
|---|
| 1702 | forEach(fn) {
|
|---|
| 1703 | utils$1.forEach(this.handlers, function forEachHandler(h) {
|
|---|
| 1704 | if (h !== null) {
|
|---|
| 1705 | fn(h);
|
|---|
| 1706 | }
|
|---|
| 1707 | });
|
|---|
| 1708 | }
|
|---|
| 1709 | }
|
|---|
| 1710 |
|
|---|
| 1711 | var transitionalDefaults = {
|
|---|
| 1712 | silentJSONParsing: true,
|
|---|
| 1713 | forcedJSONParsing: true,
|
|---|
| 1714 | clarifyTimeoutError: false,
|
|---|
| 1715 | legacyInterceptorReqResOrdering: true
|
|---|
| 1716 | };
|
|---|
| 1717 |
|
|---|
| 1718 | var URLSearchParams = url.URLSearchParams;
|
|---|
| 1719 |
|
|---|
| 1720 | const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
|---|
| 1721 | const DIGIT = '0123456789';
|
|---|
| 1722 | const ALPHABET = {
|
|---|
| 1723 | DIGIT,
|
|---|
| 1724 | ALPHA,
|
|---|
| 1725 | ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
|---|
| 1726 | };
|
|---|
| 1727 | const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|---|
| 1728 | let str = '';
|
|---|
| 1729 | const {
|
|---|
| 1730 | length
|
|---|
| 1731 | } = alphabet;
|
|---|
| 1732 | const randomValues = new Uint32Array(size);
|
|---|
| 1733 | crypto.randomFillSync(randomValues);
|
|---|
| 1734 | for (let i = 0; i < size; i++) {
|
|---|
| 1735 | str += alphabet[randomValues[i] % length];
|
|---|
| 1736 | }
|
|---|
| 1737 | return str;
|
|---|
| 1738 | };
|
|---|
| 1739 | var platform$1 = {
|
|---|
| 1740 | isNode: true,
|
|---|
| 1741 | classes: {
|
|---|
| 1742 | URLSearchParams,
|
|---|
| 1743 | FormData: FormData$1,
|
|---|
| 1744 | Blob: typeof Blob !== 'undefined' && Blob || null
|
|---|
| 1745 | },
|
|---|
| 1746 | ALPHABET,
|
|---|
| 1747 | generateString,
|
|---|
| 1748 | protocols: ['http', 'https', 'file', 'data']
|
|---|
| 1749 | };
|
|---|
| 1750 |
|
|---|
| 1751 | const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|---|
| 1752 | const _navigator = typeof navigator === 'object' && navigator || undefined;
|
|---|
| 1753 |
|
|---|
| 1754 | /**
|
|---|
| 1755 | * Determine if we're running in a standard browser environment
|
|---|
| 1756 | *
|
|---|
| 1757 | * This allows axios to run in a web worker, and react-native.
|
|---|
| 1758 | * Both environments support XMLHttpRequest, but not fully standard globals.
|
|---|
| 1759 | *
|
|---|
| 1760 | * web workers:
|
|---|
| 1761 | * typeof window -> undefined
|
|---|
| 1762 | * typeof document -> undefined
|
|---|
| 1763 | *
|
|---|
| 1764 | * react-native:
|
|---|
| 1765 | * navigator.product -> 'ReactNative'
|
|---|
| 1766 | * nativescript
|
|---|
| 1767 | * navigator.product -> 'NativeScript' or 'NS'
|
|---|
| 1768 | *
|
|---|
| 1769 | * @returns {boolean}
|
|---|
| 1770 | */
|
|---|
| 1771 | const hasStandardBrowserEnv = hasBrowserEnv && (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
|
|---|
| 1772 |
|
|---|
| 1773 | /**
|
|---|
| 1774 | * Determine if we're running in a standard browser webWorker environment
|
|---|
| 1775 | *
|
|---|
| 1776 | * Although the `isStandardBrowserEnv` method indicates that
|
|---|
| 1777 | * `allows axios to run in a web worker`, the WebWorker will still be
|
|---|
| 1778 | * filtered out due to its judgment standard
|
|---|
| 1779 | * `typeof window !== 'undefined' && typeof document !== 'undefined'`.
|
|---|
| 1780 | * This leads to a problem when axios post `FormData` in webWorker
|
|---|
| 1781 | */
|
|---|
| 1782 | const hasStandardBrowserWebWorkerEnv = (() => {
|
|---|
| 1783 | return typeof WorkerGlobalScope !== 'undefined' &&
|
|---|
| 1784 | // eslint-disable-next-line no-undef
|
|---|
| 1785 | self instanceof WorkerGlobalScope && typeof self.importScripts === 'function';
|
|---|
| 1786 | })();
|
|---|
| 1787 | const origin = hasBrowserEnv && window.location.href || 'http://localhost';
|
|---|
| 1788 |
|
|---|
| 1789 | var utils = /*#__PURE__*/Object.freeze({
|
|---|
| 1790 | __proto__: null,
|
|---|
| 1791 | hasBrowserEnv: hasBrowserEnv,
|
|---|
| 1792 | hasStandardBrowserEnv: hasStandardBrowserEnv,
|
|---|
| 1793 | hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
|
|---|
| 1794 | navigator: _navigator,
|
|---|
| 1795 | origin: origin
|
|---|
| 1796 | });
|
|---|
| 1797 |
|
|---|
| 1798 | var platform = {
|
|---|
| 1799 | ...utils,
|
|---|
| 1800 | ...platform$1
|
|---|
| 1801 | };
|
|---|
| 1802 |
|
|---|
| 1803 | function toURLEncodedForm(data, options) {
|
|---|
| 1804 | return toFormData(data, new platform.classes.URLSearchParams(), {
|
|---|
| 1805 | visitor: function (value, key, path, helpers) {
|
|---|
| 1806 | if (platform.isNode && utils$1.isBuffer(value)) {
|
|---|
| 1807 | this.append(key, value.toString('base64'));
|
|---|
| 1808 | return false;
|
|---|
| 1809 | }
|
|---|
| 1810 | return helpers.defaultVisitor.apply(this, arguments);
|
|---|
| 1811 | },
|
|---|
| 1812 | ...options
|
|---|
| 1813 | });
|
|---|
| 1814 | }
|
|---|
| 1815 |
|
|---|
| 1816 | /**
|
|---|
| 1817 | * It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
|
|---|
| 1818 | *
|
|---|
| 1819 | * @param {string} name - The name of the property to get.
|
|---|
| 1820 | *
|
|---|
| 1821 | * @returns An array of strings.
|
|---|
| 1822 | */
|
|---|
| 1823 | function parsePropPath(name) {
|
|---|
| 1824 | // foo[x][y][z]
|
|---|
| 1825 | // foo.x.y.z
|
|---|
| 1826 | // foo-x-y-z
|
|---|
| 1827 | // foo x y z
|
|---|
| 1828 | return utils$1.matchAll(/\w+|\[(\w*)]/g, name).map(match => {
|
|---|
| 1829 | return match[0] === '[]' ? '' : match[1] || match[0];
|
|---|
| 1830 | });
|
|---|
| 1831 | }
|
|---|
| 1832 |
|
|---|
| 1833 | /**
|
|---|
| 1834 | * Convert an array to an object.
|
|---|
| 1835 | *
|
|---|
| 1836 | * @param {Array<any>} arr - The array to convert to an object.
|
|---|
| 1837 | *
|
|---|
| 1838 | * @returns An object with the same keys and values as the array.
|
|---|
| 1839 | */
|
|---|
| 1840 | function arrayToObject(arr) {
|
|---|
| 1841 | const obj = {};
|
|---|
| 1842 | const keys = Object.keys(arr);
|
|---|
| 1843 | let i;
|
|---|
| 1844 | const len = keys.length;
|
|---|
| 1845 | let key;
|
|---|
| 1846 | for (i = 0; i < len; i++) {
|
|---|
| 1847 | key = keys[i];
|
|---|
| 1848 | obj[key] = arr[key];
|
|---|
| 1849 | }
|
|---|
| 1850 | return obj;
|
|---|
| 1851 | }
|
|---|
| 1852 |
|
|---|
| 1853 | /**
|
|---|
| 1854 | * It takes a FormData object and returns a JavaScript object
|
|---|
| 1855 | *
|
|---|
| 1856 | * @param {string} formData The FormData object to convert to JSON.
|
|---|
| 1857 | *
|
|---|
| 1858 | * @returns {Object<string, any> | null} The converted object.
|
|---|
| 1859 | */
|
|---|
| 1860 | function formDataToJSON(formData) {
|
|---|
| 1861 | function buildPath(path, value, target, index) {
|
|---|
| 1862 | let name = path[index++];
|
|---|
| 1863 | if (name === '__proto__') return true;
|
|---|
| 1864 | const isNumericKey = Number.isFinite(+name);
|
|---|
| 1865 | const isLast = index >= path.length;
|
|---|
| 1866 | name = !name && utils$1.isArray(target) ? target.length : name;
|
|---|
| 1867 | if (isLast) {
|
|---|
| 1868 | if (utils$1.hasOwnProp(target, name)) {
|
|---|
| 1869 | target[name] = utils$1.isArray(target[name]) ? target[name].concat(value) : [target[name], value];
|
|---|
| 1870 | } else {
|
|---|
| 1871 | target[name] = value;
|
|---|
| 1872 | }
|
|---|
| 1873 | return !isNumericKey;
|
|---|
| 1874 | }
|
|---|
| 1875 | if (!utils$1.hasOwnProp(target, name) || !utils$1.isObject(target[name])) {
|
|---|
| 1876 | target[name] = [];
|
|---|
| 1877 | }
|
|---|
| 1878 | const result = buildPath(path, value, target[name], index);
|
|---|
| 1879 | if (result && utils$1.isArray(target[name])) {
|
|---|
| 1880 | target[name] = arrayToObject(target[name]);
|
|---|
| 1881 | }
|
|---|
| 1882 | return !isNumericKey;
|
|---|
| 1883 | }
|
|---|
| 1884 | if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
|
|---|
| 1885 | const obj = {};
|
|---|
| 1886 | utils$1.forEachEntry(formData, (name, value) => {
|
|---|
| 1887 | buildPath(parsePropPath(name), value, obj, 0);
|
|---|
| 1888 | });
|
|---|
| 1889 | return obj;
|
|---|
| 1890 | }
|
|---|
| 1891 | return null;
|
|---|
| 1892 | }
|
|---|
| 1893 |
|
|---|
| 1894 | const own = (obj, key) => obj != null && utils$1.hasOwnProp(obj, key) ? obj[key] : undefined;
|
|---|
| 1895 |
|
|---|
| 1896 | /**
|
|---|
| 1897 | * It takes a string, tries to parse it, and if it fails, it returns the stringified version
|
|---|
| 1898 | * of the input
|
|---|
| 1899 | *
|
|---|
| 1900 | * @param {any} rawValue - The value to be stringified.
|
|---|
| 1901 | * @param {Function} parser - A function that parses a string into a JavaScript object.
|
|---|
| 1902 | * @param {Function} encoder - A function that takes a value and returns a string.
|
|---|
| 1903 | *
|
|---|
| 1904 | * @returns {string} A stringified version of the rawValue.
|
|---|
| 1905 | */
|
|---|
| 1906 | function stringifySafely(rawValue, parser, encoder) {
|
|---|
| 1907 | if (utils$1.isString(rawValue)) {
|
|---|
| 1908 | try {
|
|---|
| 1909 | (parser || JSON.parse)(rawValue);
|
|---|
| 1910 | return utils$1.trim(rawValue);
|
|---|
| 1911 | } catch (e) {
|
|---|
| 1912 | if (e.name !== 'SyntaxError') {
|
|---|
| 1913 | throw e;
|
|---|
| 1914 | }
|
|---|
| 1915 | }
|
|---|
| 1916 | }
|
|---|
| 1917 | return (encoder || JSON.stringify)(rawValue);
|
|---|
| 1918 | }
|
|---|
| 1919 | const defaults = {
|
|---|
| 1920 | transitional: transitionalDefaults,
|
|---|
| 1921 | adapter: ['xhr', 'http', 'fetch'],
|
|---|
| 1922 | transformRequest: [function transformRequest(data, headers) {
|
|---|
| 1923 | const contentType = headers.getContentType() || '';
|
|---|
| 1924 | const hasJSONContentType = contentType.indexOf('application/json') > -1;
|
|---|
| 1925 | const isObjectPayload = utils$1.isObject(data);
|
|---|
| 1926 | if (isObjectPayload && utils$1.isHTMLForm(data)) {
|
|---|
| 1927 | data = new FormData(data);
|
|---|
| 1928 | }
|
|---|
| 1929 | const isFormData = utils$1.isFormData(data);
|
|---|
| 1930 | if (isFormData) {
|
|---|
| 1931 | return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
|
|---|
| 1932 | }
|
|---|
| 1933 | if (utils$1.isArrayBuffer(data) || utils$1.isBuffer(data) || utils$1.isStream(data) || utils$1.isFile(data) || utils$1.isBlob(data) || utils$1.isReadableStream(data)) {
|
|---|
| 1934 | return data;
|
|---|
| 1935 | }
|
|---|
| 1936 | if (utils$1.isArrayBufferView(data)) {
|
|---|
| 1937 | return data.buffer;
|
|---|
| 1938 | }
|
|---|
| 1939 | if (utils$1.isURLSearchParams(data)) {
|
|---|
| 1940 | headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
|
|---|
| 1941 | return data.toString();
|
|---|
| 1942 | }
|
|---|
| 1943 | let isFileList;
|
|---|
| 1944 | if (isObjectPayload) {
|
|---|
| 1945 | const formSerializer = own(this, 'formSerializer');
|
|---|
| 1946 | if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
|
|---|
| 1947 | return toURLEncodedForm(data, formSerializer).toString();
|
|---|
| 1948 | }
|
|---|
| 1949 | if ((isFileList = utils$1.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
|
|---|
| 1950 | const env = own(this, 'env');
|
|---|
| 1951 | const _FormData = env && env.FormData;
|
|---|
| 1952 | return toFormData(isFileList ? {
|
|---|
| 1953 | 'files[]': data
|
|---|
| 1954 | } : data, _FormData && new _FormData(), formSerializer);
|
|---|
| 1955 | }
|
|---|
| 1956 | }
|
|---|
| 1957 | if (isObjectPayload || hasJSONContentType) {
|
|---|
| 1958 | headers.setContentType('application/json', false);
|
|---|
| 1959 | return stringifySafely(data);
|
|---|
| 1960 | }
|
|---|
| 1961 | return data;
|
|---|
| 1962 | }],
|
|---|
| 1963 | transformResponse: [function transformResponse(data) {
|
|---|
| 1964 | const transitional = own(this, 'transitional') || defaults.transitional;
|
|---|
| 1965 | const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
|
|---|
| 1966 | const responseType = own(this, 'responseType');
|
|---|
| 1967 | const JSONRequested = responseType === 'json';
|
|---|
| 1968 | if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
|
|---|
| 1969 | return data;
|
|---|
| 1970 | }
|
|---|
| 1971 | if (data && utils$1.isString(data) && (forcedJSONParsing && !responseType || JSONRequested)) {
|
|---|
| 1972 | const silentJSONParsing = transitional && transitional.silentJSONParsing;
|
|---|
| 1973 | const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
|---|
| 1974 | try {
|
|---|
| 1975 | return JSON.parse(data, own(this, 'parseReviver'));
|
|---|
| 1976 | } catch (e) {
|
|---|
| 1977 | if (strictJSONParsing) {
|
|---|
| 1978 | if (e.name === 'SyntaxError') {
|
|---|
| 1979 | throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, own(this, 'response'));
|
|---|
| 1980 | }
|
|---|
| 1981 | throw e;
|
|---|
| 1982 | }
|
|---|
| 1983 | }
|
|---|
| 1984 | }
|
|---|
| 1985 | return data;
|
|---|
| 1986 | }],
|
|---|
| 1987 | /**
|
|---|
| 1988 | * A timeout in milliseconds to abort a request. If set to 0 (default) a
|
|---|
| 1989 | * timeout is not created.
|
|---|
| 1990 | */
|
|---|
| 1991 | timeout: 0,
|
|---|
| 1992 | xsrfCookieName: 'XSRF-TOKEN',
|
|---|
| 1993 | xsrfHeaderName: 'X-XSRF-TOKEN',
|
|---|
| 1994 | maxContentLength: -1,
|
|---|
| 1995 | maxBodyLength: -1,
|
|---|
| 1996 | env: {
|
|---|
| 1997 | FormData: platform.classes.FormData,
|
|---|
| 1998 | Blob: platform.classes.Blob
|
|---|
| 1999 | },
|
|---|
| 2000 | validateStatus: function validateStatus(status) {
|
|---|
| 2001 | return status >= 200 && status < 300;
|
|---|
| 2002 | },
|
|---|
| 2003 | headers: {
|
|---|
| 2004 | common: {
|
|---|
| 2005 | Accept: 'application/json, text/plain, */*',
|
|---|
| 2006 | 'Content-Type': undefined
|
|---|
| 2007 | }
|
|---|
| 2008 | }
|
|---|
| 2009 | };
|
|---|
| 2010 | utils$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'query'], method => {
|
|---|
| 2011 | defaults.headers[method] = {};
|
|---|
| 2012 | });
|
|---|
| 2013 |
|
|---|
| 2014 | /**
|
|---|
| 2015 | * Transform the data for a request or a response
|
|---|
| 2016 | *
|
|---|
| 2017 | * @param {Array|Function} fns A single function or Array of functions
|
|---|
| 2018 | * @param {?Object} response The response object
|
|---|
| 2019 | *
|
|---|
| 2020 | * @returns {*} The resulting transformed data
|
|---|
| 2021 | */
|
|---|
| 2022 | function transformData(fns, response) {
|
|---|
| 2023 | const config = this || defaults;
|
|---|
| 2024 | const context = response || config;
|
|---|
| 2025 | const headers = AxiosHeaders.from(context.headers);
|
|---|
| 2026 | let data = context.data;
|
|---|
| 2027 | utils$1.forEach(fns, function transform(fn) {
|
|---|
| 2028 | data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
|
|---|
| 2029 | });
|
|---|
| 2030 | headers.normalize();
|
|---|
| 2031 | return data;
|
|---|
| 2032 | }
|
|---|
| 2033 |
|
|---|
| 2034 | function isCancel(value) {
|
|---|
| 2035 | return !!(value && value.__CANCEL__);
|
|---|
| 2036 | }
|
|---|
| 2037 |
|
|---|
| 2038 | class CanceledError extends AxiosError {
|
|---|
| 2039 | /**
|
|---|
| 2040 | * A `CanceledError` is an object that is thrown when an operation is canceled.
|
|---|
| 2041 | *
|
|---|
| 2042 | * @param {string=} message The message.
|
|---|
| 2043 | * @param {Object=} config The config.
|
|---|
| 2044 | * @param {Object=} request The request.
|
|---|
| 2045 | *
|
|---|
| 2046 | * @returns {CanceledError} The created error.
|
|---|
| 2047 | */
|
|---|
| 2048 | constructor(message, config, request) {
|
|---|
| 2049 | super(message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
|
|---|
| 2050 | this.name = 'CanceledError';
|
|---|
| 2051 | this.__CANCEL__ = true;
|
|---|
| 2052 | }
|
|---|
| 2053 | }
|
|---|
| 2054 |
|
|---|
| 2055 | /**
|
|---|
| 2056 | * Resolve or reject a Promise based on response status.
|
|---|
| 2057 | *
|
|---|
| 2058 | * @param {Function} resolve A function that resolves the promise.
|
|---|
| 2059 | * @param {Function} reject A function that rejects the promise.
|
|---|
| 2060 | * @param {object} response The response.
|
|---|
| 2061 | *
|
|---|
| 2062 | * @returns {object} The response.
|
|---|
| 2063 | */
|
|---|
| 2064 | function settle(resolve, reject, response) {
|
|---|
| 2065 | const validateStatus = response.config.validateStatus;
|
|---|
| 2066 | if (!response.status || !validateStatus || validateStatus(response.status)) {
|
|---|
| 2067 | resolve(response);
|
|---|
| 2068 | } else {
|
|---|
| 2069 | reject(new AxiosError('Request failed with status code ' + response.status, response.status >= 400 && response.status < 500 ? AxiosError.ERR_BAD_REQUEST : AxiosError.ERR_BAD_RESPONSE, response.config, response.request, response));
|
|---|
| 2070 | }
|
|---|
| 2071 | }
|
|---|
| 2072 |
|
|---|
| 2073 | /**
|
|---|
| 2074 | * Determines whether the specified URL is absolute
|
|---|
| 2075 | *
|
|---|
| 2076 | * @param {string} url The URL to test
|
|---|
| 2077 | *
|
|---|
| 2078 | * @returns {boolean} True if the specified URL is absolute, otherwise false
|
|---|
| 2079 | */
|
|---|
| 2080 | function isAbsoluteURL(url) {
|
|---|
| 2081 | // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
|---|
| 2082 | // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
|---|
| 2083 | // by any combination of letters, digits, plus, period, or hyphen.
|
|---|
| 2084 | if (typeof url !== 'string') {
|
|---|
| 2085 | return false;
|
|---|
| 2086 | }
|
|---|
| 2087 | return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
|---|
| 2088 | }
|
|---|
| 2089 |
|
|---|
| 2090 | /**
|
|---|
| 2091 | * Creates a new URL by combining the specified URLs
|
|---|
| 2092 | *
|
|---|
| 2093 | * @param {string} baseURL The base URL
|
|---|
| 2094 | * @param {string} relativeURL The relative URL
|
|---|
| 2095 | *
|
|---|
| 2096 | * @returns {string} The combined URL
|
|---|
| 2097 | */
|
|---|
| 2098 | function combineURLs(baseURL, relativeURL) {
|
|---|
| 2099 | return relativeURL ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '') : baseURL;
|
|---|
| 2100 | }
|
|---|
| 2101 |
|
|---|
| 2102 | /**
|
|---|
| 2103 | * Creates a new URL by combining the baseURL with the requestedURL,
|
|---|
| 2104 | * only when the requestedURL is not already an absolute URL.
|
|---|
| 2105 | * If the requestURL is absolute, this function returns the requestedURL untouched.
|
|---|
| 2106 | *
|
|---|
| 2107 | * @param {string} baseURL The base URL
|
|---|
| 2108 | * @param {string} requestedURL Absolute or relative URL to combine
|
|---|
| 2109 | *
|
|---|
| 2110 | * @returns {string} The combined full path
|
|---|
| 2111 | */
|
|---|
| 2112 | function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
|
|---|
| 2113 | let isRelativeUrl = !isAbsoluteURL(requestedURL);
|
|---|
| 2114 | if (baseURL && (isRelativeUrl || allowAbsoluteUrls === false)) {
|
|---|
| 2115 | return combineURLs(baseURL, requestedURL);
|
|---|
| 2116 | }
|
|---|
| 2117 | return requestedURL;
|
|---|
| 2118 | }
|
|---|
| 2119 |
|
|---|
| 2120 | var DEFAULT_PORTS$1 = {
|
|---|
| 2121 | ftp: 21,
|
|---|
| 2122 | gopher: 70,
|
|---|
| 2123 | http: 80,
|
|---|
| 2124 | https: 443,
|
|---|
| 2125 | ws: 80,
|
|---|
| 2126 | wss: 443
|
|---|
| 2127 | };
|
|---|
| 2128 | function parseUrl(urlString) {
|
|---|
| 2129 | try {
|
|---|
| 2130 | return new URL(urlString);
|
|---|
| 2131 | } catch {
|
|---|
| 2132 | return null;
|
|---|
| 2133 | }
|
|---|
| 2134 | }
|
|---|
| 2135 |
|
|---|
| 2136 | /**
|
|---|
| 2137 | * @param {string|object|URL} url - The URL as a string or URL instance, or a
|
|---|
| 2138 | * compatible object (such as the result from legacy url.parse).
|
|---|
| 2139 | * @return {string} The URL of the proxy that should handle the request to the
|
|---|
| 2140 | * given URL. If no proxy is set, this will be an empty string.
|
|---|
| 2141 | */
|
|---|
| 2142 | function getProxyForUrl(url) {
|
|---|
| 2143 | var parsedUrl = (typeof url === 'string' ? parseUrl(url) : url) || {};
|
|---|
| 2144 | var proto = parsedUrl.protocol;
|
|---|
| 2145 | var hostname = parsedUrl.host;
|
|---|
| 2146 | var port = parsedUrl.port;
|
|---|
| 2147 | if (typeof hostname !== 'string' || !hostname || typeof proto !== 'string') {
|
|---|
| 2148 | return ''; // Don't proxy URLs without a valid scheme or host.
|
|---|
| 2149 | }
|
|---|
| 2150 | proto = proto.split(':', 1)[0];
|
|---|
| 2151 | // Stripping ports in this way instead of using parsedUrl.hostname to make
|
|---|
| 2152 | // sure that the brackets around IPv6 addresses are kept.
|
|---|
| 2153 | hostname = hostname.replace(/:\d*$/, '');
|
|---|
| 2154 | port = parseInt(port) || DEFAULT_PORTS$1[proto] || 0;
|
|---|
| 2155 | if (!shouldProxy(hostname, port)) {
|
|---|
| 2156 | return ''; // Don't proxy URLs that match NO_PROXY.
|
|---|
| 2157 | }
|
|---|
| 2158 | var proxy = getEnv(proto + '_proxy') || getEnv('all_proxy');
|
|---|
| 2159 | if (proxy && proxy.indexOf('://') === -1) {
|
|---|
| 2160 | // Missing scheme in proxy, default to the requested URL's scheme.
|
|---|
| 2161 | proxy = proto + '://' + proxy;
|
|---|
| 2162 | }
|
|---|
| 2163 | return proxy;
|
|---|
| 2164 | }
|
|---|
| 2165 |
|
|---|
| 2166 | /**
|
|---|
| 2167 | * Determines whether a given URL should be proxied.
|
|---|
| 2168 | *
|
|---|
| 2169 | * @param {string} hostname - The host name of the URL.
|
|---|
| 2170 | * @param {number} port - The effective port of the URL.
|
|---|
| 2171 | * @returns {boolean} Whether the given URL should be proxied.
|
|---|
| 2172 | * @private
|
|---|
| 2173 | */
|
|---|
| 2174 | function shouldProxy(hostname, port) {
|
|---|
| 2175 | var NO_PROXY = getEnv('no_proxy').toLowerCase();
|
|---|
| 2176 | if (!NO_PROXY) {
|
|---|
| 2177 | return true; // Always proxy if NO_PROXY is not set.
|
|---|
| 2178 | }
|
|---|
| 2179 | if (NO_PROXY === '*') {
|
|---|
| 2180 | return false; // Never proxy if wildcard is set.
|
|---|
| 2181 | }
|
|---|
| 2182 | return NO_PROXY.split(/[,\s]/).every(function (proxy) {
|
|---|
| 2183 | if (!proxy) {
|
|---|
| 2184 | return true; // Skip zero-length hosts.
|
|---|
| 2185 | }
|
|---|
| 2186 | var parsedProxy = proxy.match(/^(.+):(\d+)$/);
|
|---|
| 2187 | var parsedProxyHostname = parsedProxy ? parsedProxy[1] : proxy;
|
|---|
| 2188 | var parsedProxyPort = parsedProxy ? parseInt(parsedProxy[2]) : 0;
|
|---|
| 2189 | if (parsedProxyPort && parsedProxyPort !== port) {
|
|---|
| 2190 | return true; // Skip if ports don't match.
|
|---|
| 2191 | }
|
|---|
| 2192 | if (!/^[.*]/.test(parsedProxyHostname)) {
|
|---|
| 2193 | // No wildcards, so stop proxying if there is an exact match.
|
|---|
| 2194 | return hostname !== parsedProxyHostname;
|
|---|
| 2195 | }
|
|---|
| 2196 | if (parsedProxyHostname.charAt(0) === '*') {
|
|---|
| 2197 | // Remove leading wildcard.
|
|---|
| 2198 | parsedProxyHostname = parsedProxyHostname.slice(1);
|
|---|
| 2199 | }
|
|---|
| 2200 | // Stop proxying if the hostname ends with the no_proxy host.
|
|---|
| 2201 | return !hostname.endsWith(parsedProxyHostname);
|
|---|
| 2202 | });
|
|---|
| 2203 | }
|
|---|
| 2204 |
|
|---|
| 2205 | /**
|
|---|
| 2206 | * Get the value for an environment variable.
|
|---|
| 2207 | *
|
|---|
| 2208 | * @param {string} key - The name of the environment variable.
|
|---|
| 2209 | * @return {string} The value of the environment variable.
|
|---|
| 2210 | * @private
|
|---|
| 2211 | */
|
|---|
| 2212 | function getEnv(key) {
|
|---|
| 2213 | return process.env[key.toLowerCase()] || process.env[key.toUpperCase()] || '';
|
|---|
| 2214 | }
|
|---|
| 2215 |
|
|---|
| 2216 | const VERSION = "1.16.1";
|
|---|
| 2217 |
|
|---|
| 2218 | function parseProtocol(url) {
|
|---|
| 2219 | const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url);
|
|---|
| 2220 | return match && match[1] || '';
|
|---|
| 2221 | }
|
|---|
| 2222 |
|
|---|
| 2223 | // RFC 2397: data:[<mediatype>][;base64],<data>
|
|---|
| 2224 | // mediatype = type/subtype followed by optional ;name=value parameters
|
|---|
| 2225 | const DATA_URL_PATTERN = /^([^,;]+\/[^,;]+)?((?:;[^,;=]+=[^,;]+)*)(;base64)?,([\s\S]*)$/;
|
|---|
| 2226 |
|
|---|
| 2227 | /**
|
|---|
| 2228 | * Parse data uri to a Buffer or Blob
|
|---|
| 2229 | *
|
|---|
| 2230 | * @param {String} uri
|
|---|
| 2231 | * @param {?Boolean} asBlob
|
|---|
| 2232 | * @param {?Object} options
|
|---|
| 2233 | * @param {?Function} options.Blob
|
|---|
| 2234 | *
|
|---|
| 2235 | * @returns {Buffer|Blob}
|
|---|
| 2236 | */
|
|---|
| 2237 | function fromDataURI(uri, asBlob, options) {
|
|---|
| 2238 | const _Blob = options && options.Blob || platform.classes.Blob;
|
|---|
| 2239 | const protocol = parseProtocol(uri);
|
|---|
| 2240 | if (asBlob === undefined && _Blob) {
|
|---|
| 2241 | asBlob = true;
|
|---|
| 2242 | }
|
|---|
| 2243 | if (protocol === 'data') {
|
|---|
| 2244 | uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
|
|---|
| 2245 | const match = DATA_URL_PATTERN.exec(uri);
|
|---|
| 2246 | if (!match) {
|
|---|
| 2247 | throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
|
|---|
| 2248 | }
|
|---|
| 2249 | const type = match[1];
|
|---|
| 2250 | const params = match[2];
|
|---|
| 2251 | const encoding = match[3] ? 'base64' : 'utf8';
|
|---|
| 2252 | const body = match[4];
|
|---|
| 2253 |
|
|---|
| 2254 | // RFC 2397 section 3: default mediatype is text/plain;charset=US-ASCII
|
|---|
| 2255 | // Bare `data:,` leaves mime undefined; Blob normalises that to "" per spec.
|
|---|
| 2256 | let mime;
|
|---|
| 2257 | if (type) {
|
|---|
| 2258 | mime = params ? type + params : type;
|
|---|
| 2259 | } else if (params) {
|
|---|
| 2260 | mime = 'text/plain' + params;
|
|---|
| 2261 | }
|
|---|
| 2262 | const buffer = Buffer.from(decodeURIComponent(body), encoding);
|
|---|
| 2263 | if (asBlob) {
|
|---|
| 2264 | if (!_Blob) {
|
|---|
| 2265 | throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
|
|---|
| 2266 | }
|
|---|
| 2267 | return new _Blob([buffer], {
|
|---|
| 2268 | type: mime
|
|---|
| 2269 | });
|
|---|
| 2270 | }
|
|---|
| 2271 | return buffer;
|
|---|
| 2272 | }
|
|---|
| 2273 | throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
|
|---|
| 2274 | }
|
|---|
| 2275 |
|
|---|
| 2276 | const kInternals = Symbol('internals');
|
|---|
| 2277 | class AxiosTransformStream extends stream.Transform {
|
|---|
| 2278 | constructor(options) {
|
|---|
| 2279 | options = utils$1.toFlatObject(options, {
|
|---|
| 2280 | maxRate: 0,
|
|---|
| 2281 | chunkSize: 64 * 1024,
|
|---|
| 2282 | minChunkSize: 100,
|
|---|
| 2283 | timeWindow: 500,
|
|---|
| 2284 | ticksRate: 2,
|
|---|
| 2285 | samplesCount: 15
|
|---|
| 2286 | }, null, (prop, source) => {
|
|---|
| 2287 | return !utils$1.isUndefined(source[prop]);
|
|---|
| 2288 | });
|
|---|
| 2289 | super({
|
|---|
| 2290 | readableHighWaterMark: options.chunkSize
|
|---|
| 2291 | });
|
|---|
| 2292 | const internals = this[kInternals] = {
|
|---|
| 2293 | timeWindow: options.timeWindow,
|
|---|
| 2294 | chunkSize: options.chunkSize,
|
|---|
| 2295 | maxRate: options.maxRate,
|
|---|
| 2296 | minChunkSize: options.minChunkSize,
|
|---|
| 2297 | bytesSeen: 0,
|
|---|
| 2298 | isCaptured: false,
|
|---|
| 2299 | notifiedBytesLoaded: 0,
|
|---|
| 2300 | ts: Date.now(),
|
|---|
| 2301 | bytes: 0,
|
|---|
| 2302 | onReadCallback: null
|
|---|
| 2303 | };
|
|---|
| 2304 | this.on('newListener', event => {
|
|---|
| 2305 | if (event === 'progress') {
|
|---|
| 2306 | if (!internals.isCaptured) {
|
|---|
| 2307 | internals.isCaptured = true;
|
|---|
| 2308 | }
|
|---|
| 2309 | }
|
|---|
| 2310 | });
|
|---|
| 2311 | }
|
|---|
| 2312 | _read(size) {
|
|---|
| 2313 | const internals = this[kInternals];
|
|---|
| 2314 | if (internals.onReadCallback) {
|
|---|
| 2315 | internals.onReadCallback();
|
|---|
| 2316 | }
|
|---|
| 2317 | return super._read(size);
|
|---|
| 2318 | }
|
|---|
| 2319 | _transform(chunk, encoding, callback) {
|
|---|
| 2320 | const internals = this[kInternals];
|
|---|
| 2321 | const maxRate = internals.maxRate;
|
|---|
| 2322 | const readableHighWaterMark = this.readableHighWaterMark;
|
|---|
| 2323 | const timeWindow = internals.timeWindow;
|
|---|
| 2324 | const divider = 1000 / timeWindow;
|
|---|
| 2325 | const bytesThreshold = maxRate / divider;
|
|---|
| 2326 | const minChunkSize = internals.minChunkSize !== false ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) : 0;
|
|---|
| 2327 | const pushChunk = (_chunk, _callback) => {
|
|---|
| 2328 | const bytes = Buffer.byteLength(_chunk);
|
|---|
| 2329 | internals.bytesSeen += bytes;
|
|---|
| 2330 | internals.bytes += bytes;
|
|---|
| 2331 | internals.isCaptured && this.emit('progress', internals.bytesSeen);
|
|---|
| 2332 | if (this.push(_chunk)) {
|
|---|
| 2333 | process.nextTick(_callback);
|
|---|
| 2334 | } else {
|
|---|
| 2335 | internals.onReadCallback = () => {
|
|---|
| 2336 | internals.onReadCallback = null;
|
|---|
| 2337 | process.nextTick(_callback);
|
|---|
| 2338 | };
|
|---|
| 2339 | }
|
|---|
| 2340 | };
|
|---|
| 2341 | const transformChunk = (_chunk, _callback) => {
|
|---|
| 2342 | const chunkSize = Buffer.byteLength(_chunk);
|
|---|
| 2343 | let chunkRemainder = null;
|
|---|
| 2344 | let maxChunkSize = readableHighWaterMark;
|
|---|
| 2345 | let bytesLeft;
|
|---|
| 2346 | let passed = 0;
|
|---|
| 2347 | if (maxRate) {
|
|---|
| 2348 | const now = Date.now();
|
|---|
| 2349 | if (!internals.ts || (passed = now - internals.ts) >= timeWindow) {
|
|---|
| 2350 | internals.ts = now;
|
|---|
| 2351 | bytesLeft = bytesThreshold - internals.bytes;
|
|---|
| 2352 | internals.bytes = bytesLeft < 0 ? -bytesLeft : 0;
|
|---|
| 2353 | passed = 0;
|
|---|
| 2354 | }
|
|---|
| 2355 | bytesLeft = bytesThreshold - internals.bytes;
|
|---|
| 2356 | }
|
|---|
| 2357 | if (maxRate) {
|
|---|
| 2358 | if (bytesLeft <= 0) {
|
|---|
| 2359 | // next time window
|
|---|
| 2360 | return setTimeout(() => {
|
|---|
| 2361 | _callback(null, _chunk);
|
|---|
| 2362 | }, timeWindow - passed);
|
|---|
| 2363 | }
|
|---|
| 2364 | if (bytesLeft < maxChunkSize) {
|
|---|
| 2365 | maxChunkSize = bytesLeft;
|
|---|
| 2366 | }
|
|---|
| 2367 | }
|
|---|
| 2368 | if (maxChunkSize && chunkSize > maxChunkSize && chunkSize - maxChunkSize > minChunkSize) {
|
|---|
| 2369 | chunkRemainder = _chunk.subarray(maxChunkSize);
|
|---|
| 2370 | _chunk = _chunk.subarray(0, maxChunkSize);
|
|---|
| 2371 | }
|
|---|
| 2372 | pushChunk(_chunk, chunkRemainder ? () => {
|
|---|
| 2373 | process.nextTick(_callback, null, chunkRemainder);
|
|---|
| 2374 | } : _callback);
|
|---|
| 2375 | };
|
|---|
| 2376 | transformChunk(chunk, function transformNextChunk(err, _chunk) {
|
|---|
| 2377 | if (err) {
|
|---|
| 2378 | return callback(err);
|
|---|
| 2379 | }
|
|---|
| 2380 | if (_chunk) {
|
|---|
| 2381 | transformChunk(_chunk, transformNextChunk);
|
|---|
| 2382 | } else {
|
|---|
| 2383 | callback(null);
|
|---|
| 2384 | }
|
|---|
| 2385 | });
|
|---|
| 2386 | }
|
|---|
| 2387 | }
|
|---|
| 2388 |
|
|---|
| 2389 | const {
|
|---|
| 2390 | asyncIterator
|
|---|
| 2391 | } = Symbol;
|
|---|
| 2392 | const readBlob = async function* (blob) {
|
|---|
| 2393 | if (blob.stream) {
|
|---|
| 2394 | yield* blob.stream();
|
|---|
| 2395 | } else if (blob.arrayBuffer) {
|
|---|
| 2396 | yield await blob.arrayBuffer();
|
|---|
| 2397 | } else if (blob[asyncIterator]) {
|
|---|
| 2398 | yield* blob[asyncIterator]();
|
|---|
| 2399 | } else {
|
|---|
| 2400 | yield blob;
|
|---|
| 2401 | }
|
|---|
| 2402 | };
|
|---|
| 2403 |
|
|---|
| 2404 | const BOUNDARY_ALPHABET = platform.ALPHABET.ALPHA_DIGIT + '-_';
|
|---|
| 2405 | const textEncoder = typeof TextEncoder === 'function' ? new TextEncoder() : new util.TextEncoder();
|
|---|
| 2406 | const CRLF = '\r\n';
|
|---|
| 2407 | const CRLF_BYTES = textEncoder.encode(CRLF);
|
|---|
| 2408 | const CRLF_BYTES_COUNT = 2;
|
|---|
| 2409 | class FormDataPart {
|
|---|
| 2410 | constructor(name, value) {
|
|---|
| 2411 | const {
|
|---|
| 2412 | escapeName
|
|---|
| 2413 | } = this.constructor;
|
|---|
| 2414 | const isStringValue = utils$1.isString(value);
|
|---|
| 2415 | let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${!isStringValue && value.name ? `; filename="${escapeName(value.name)}"` : ''}${CRLF}`;
|
|---|
| 2416 | if (isStringValue) {
|
|---|
| 2417 | value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF));
|
|---|
| 2418 | } else {
|
|---|
| 2419 | const safeType = String(value.type || 'application/octet-stream').replace(/[\r\n]/g, '');
|
|---|
| 2420 | headers += `Content-Type: ${safeType}${CRLF}`;
|
|---|
| 2421 | }
|
|---|
| 2422 | this.headers = textEncoder.encode(headers + CRLF);
|
|---|
| 2423 | this.contentLength = isStringValue ? value.byteLength : value.size;
|
|---|
| 2424 | this.size = this.headers.byteLength + this.contentLength + CRLF_BYTES_COUNT;
|
|---|
| 2425 | this.name = name;
|
|---|
| 2426 | this.value = value;
|
|---|
| 2427 | }
|
|---|
| 2428 | async *encode() {
|
|---|
| 2429 | yield this.headers;
|
|---|
| 2430 | const {
|
|---|
| 2431 | value
|
|---|
| 2432 | } = this;
|
|---|
| 2433 | if (utils$1.isTypedArray(value)) {
|
|---|
| 2434 | yield value;
|
|---|
| 2435 | } else {
|
|---|
| 2436 | yield* readBlob(value);
|
|---|
| 2437 | }
|
|---|
| 2438 | yield CRLF_BYTES;
|
|---|
| 2439 | }
|
|---|
| 2440 | static escapeName(name) {
|
|---|
| 2441 | return String(name).replace(/[\r\n"]/g, match => ({
|
|---|
| 2442 | '\r': '%0D',
|
|---|
| 2443 | '\n': '%0A',
|
|---|
| 2444 | '"': '%22'
|
|---|
| 2445 | })[match]);
|
|---|
| 2446 | }
|
|---|
| 2447 | }
|
|---|
| 2448 | const formDataToStream = (form, headersHandler, options) => {
|
|---|
| 2449 | const {
|
|---|
| 2450 | tag = 'form-data-boundary',
|
|---|
| 2451 | size = 25,
|
|---|
| 2452 | boundary = tag + '-' + platform.generateString(size, BOUNDARY_ALPHABET)
|
|---|
| 2453 | } = options || {};
|
|---|
| 2454 | if (!utils$1.isFormData(form)) {
|
|---|
| 2455 | throw TypeError('FormData instance required');
|
|---|
| 2456 | }
|
|---|
| 2457 | if (boundary.length < 1 || boundary.length > 70) {
|
|---|
| 2458 | throw Error('boundary must be 1-70 characters long');
|
|---|
| 2459 | }
|
|---|
| 2460 | const boundaryBytes = textEncoder.encode('--' + boundary + CRLF);
|
|---|
| 2461 | const footerBytes = textEncoder.encode('--' + boundary + '--' + CRLF);
|
|---|
| 2462 | let contentLength = footerBytes.byteLength;
|
|---|
| 2463 | const parts = Array.from(form.entries()).map(([name, value]) => {
|
|---|
| 2464 | const part = new FormDataPart(name, value);
|
|---|
| 2465 | contentLength += part.size;
|
|---|
| 2466 | return part;
|
|---|
| 2467 | });
|
|---|
| 2468 | contentLength += boundaryBytes.byteLength * parts.length;
|
|---|
| 2469 | contentLength = utils$1.toFiniteNumber(contentLength);
|
|---|
| 2470 | const computedHeaders = {
|
|---|
| 2471 | 'Content-Type': `multipart/form-data; boundary=${boundary}`
|
|---|
| 2472 | };
|
|---|
| 2473 | if (Number.isFinite(contentLength)) {
|
|---|
| 2474 | computedHeaders['Content-Length'] = contentLength;
|
|---|
| 2475 | }
|
|---|
| 2476 | headersHandler && headersHandler(computedHeaders);
|
|---|
| 2477 | return stream.Readable.from(async function* () {
|
|---|
| 2478 | for (const part of parts) {
|
|---|
| 2479 | yield boundaryBytes;
|
|---|
| 2480 | yield* part.encode();
|
|---|
| 2481 | }
|
|---|
| 2482 | yield footerBytes;
|
|---|
| 2483 | }());
|
|---|
| 2484 | };
|
|---|
| 2485 |
|
|---|
| 2486 | class ZlibHeaderTransformStream extends stream.Transform {
|
|---|
| 2487 | __transform(chunk, encoding, callback) {
|
|---|
| 2488 | this.push(chunk);
|
|---|
| 2489 | callback();
|
|---|
| 2490 | }
|
|---|
| 2491 | _transform(chunk, encoding, callback) {
|
|---|
| 2492 | if (chunk.length !== 0) {
|
|---|
| 2493 | this._transform = this.__transform;
|
|---|
| 2494 |
|
|---|
| 2495 | // Add Default Compression headers if no zlib headers are present
|
|---|
| 2496 | if (chunk[0] !== 120) {
|
|---|
| 2497 | // Hex: 78
|
|---|
| 2498 | const header = Buffer.alloc(2);
|
|---|
| 2499 | header[0] = 120; // Hex: 78
|
|---|
| 2500 | header[1] = 156; // Hex: 9C
|
|---|
| 2501 | this.push(header, encoding);
|
|---|
| 2502 | }
|
|---|
| 2503 | }
|
|---|
| 2504 | this.__transform(chunk, encoding, callback);
|
|---|
| 2505 | }
|
|---|
| 2506 | }
|
|---|
| 2507 |
|
|---|
| 2508 | const callbackify = (fn, reducer) => {
|
|---|
| 2509 | return utils$1.isAsyncFn(fn) ? function (...args) {
|
|---|
| 2510 | const cb = args.pop();
|
|---|
| 2511 | fn.apply(this, args).then(value => {
|
|---|
| 2512 | try {
|
|---|
| 2513 | reducer ? cb(null, ...reducer(value)) : cb(null, value);
|
|---|
| 2514 | } catch (err) {
|
|---|
| 2515 | cb(err);
|
|---|
| 2516 | }
|
|---|
| 2517 | }, cb);
|
|---|
| 2518 | } : fn;
|
|---|
| 2519 | };
|
|---|
| 2520 |
|
|---|
| 2521 | const LOOPBACK_HOSTNAMES = new Set(['localhost']);
|
|---|
| 2522 | const isIPv4Loopback = host => {
|
|---|
| 2523 | const parts = host.split('.');
|
|---|
| 2524 | if (parts.length !== 4) return false;
|
|---|
| 2525 | if (parts[0] !== '127') return false;
|
|---|
| 2526 | return parts.every(p => /^\d+$/.test(p) && Number(p) >= 0 && Number(p) <= 255);
|
|---|
| 2527 | };
|
|---|
| 2528 | const isIPv6Loopback = host => {
|
|---|
| 2529 | // Collapse all-zero groups: any form of ::1 / 0:0:...:0:1
|
|---|
| 2530 | // First, strip any leading "::" by normalising with Set lookup of common forms,
|
|---|
| 2531 | // then fall back to structural check.
|
|---|
| 2532 | if (host === '::1') return true;
|
|---|
| 2533 |
|
|---|
| 2534 | // Check IPv4-mapped IPv6 loopback: ::ffff:<v4-loopback> or ::ffff:<hex-v4-loopback>
|
|---|
| 2535 | // Node's URL parser normalises ::ffff:127.0.0.1 → ::ffff:7f00:1
|
|---|
| 2536 | const v4MappedDotted = host.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i);
|
|---|
| 2537 | if (v4MappedDotted) return isIPv4Loopback(v4MappedDotted[1]);
|
|---|
| 2538 | const v4MappedHex = host.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i);
|
|---|
| 2539 | if (v4MappedHex) {
|
|---|
| 2540 | const high = parseInt(v4MappedHex[1], 16);
|
|---|
| 2541 | // High 16 bits must start with 127 (0x7f) — i.e. 0x7f00..0x7fff
|
|---|
| 2542 | return high >= 0x7f00 && high <= 0x7fff;
|
|---|
| 2543 | }
|
|---|
| 2544 |
|
|---|
| 2545 | // Full-form ::1 variants: any number of zero groups followed by trailing 1
|
|---|
| 2546 | // e.g. 0:0:0:0:0:0:0:1, 0000:...:0001
|
|---|
| 2547 | const groups = host.split(':');
|
|---|
| 2548 | if (groups.length === 8) {
|
|---|
| 2549 | for (let i = 0; i < 7; i++) {
|
|---|
| 2550 | if (!/^0+$/.test(groups[i])) return false;
|
|---|
| 2551 | }
|
|---|
| 2552 | return /^0*1$/.test(groups[7]);
|
|---|
| 2553 | }
|
|---|
| 2554 | return false;
|
|---|
| 2555 | };
|
|---|
| 2556 | const isLoopback = host => {
|
|---|
| 2557 | if (!host) return false;
|
|---|
| 2558 | if (LOOPBACK_HOSTNAMES.has(host)) return true;
|
|---|
| 2559 | if (isIPv4Loopback(host)) return true;
|
|---|
| 2560 | return isIPv6Loopback(host);
|
|---|
| 2561 | };
|
|---|
| 2562 | const DEFAULT_PORTS = {
|
|---|
| 2563 | http: 80,
|
|---|
| 2564 | https: 443,
|
|---|
| 2565 | ws: 80,
|
|---|
| 2566 | wss: 443,
|
|---|
| 2567 | ftp: 21
|
|---|
| 2568 | };
|
|---|
| 2569 | const parseNoProxyEntry = entry => {
|
|---|
| 2570 | let entryHost = entry;
|
|---|
| 2571 | let entryPort = 0;
|
|---|
| 2572 | if (entryHost.charAt(0) === '[') {
|
|---|
| 2573 | const bracketIndex = entryHost.indexOf(']');
|
|---|
| 2574 | if (bracketIndex !== -1) {
|
|---|
| 2575 | const host = entryHost.slice(1, bracketIndex);
|
|---|
| 2576 | const rest = entryHost.slice(bracketIndex + 1);
|
|---|
| 2577 | if (rest.charAt(0) === ':' && /^\d+$/.test(rest.slice(1))) {
|
|---|
| 2578 | entryPort = Number.parseInt(rest.slice(1), 10);
|
|---|
| 2579 | }
|
|---|
| 2580 | return [host, entryPort];
|
|---|
| 2581 | }
|
|---|
| 2582 | }
|
|---|
| 2583 | const firstColon = entryHost.indexOf(':');
|
|---|
| 2584 | const lastColon = entryHost.lastIndexOf(':');
|
|---|
| 2585 | if (firstColon !== -1 && firstColon === lastColon && /^\d+$/.test(entryHost.slice(lastColon + 1))) {
|
|---|
| 2586 | entryPort = Number.parseInt(entryHost.slice(lastColon + 1), 10);
|
|---|
| 2587 | entryHost = entryHost.slice(0, lastColon);
|
|---|
| 2588 | }
|
|---|
| 2589 | return [entryHost, entryPort];
|
|---|
| 2590 | };
|
|---|
| 2591 |
|
|---|
| 2592 | // Convert IPv4-mapped IPv6 (::ffff:0:0/96 prefix) to IPv4 dotted form so both
|
|---|
| 2593 | // sides of a NO_PROXY comparison see the same canonical address. Without this,
|
|---|
| 2594 | // `NO_PROXY=192.168.1.5` would not match a request to `http://[::ffff:192.168.1.5]/`
|
|---|
| 2595 | // (Node's URL parser normalises that to `[::ffff:c0a8:105]`), and vice-versa,
|
|---|
| 2596 | // allowing the proxy-bypass policy to be circumvented by using the alternate
|
|---|
| 2597 | // representation. Returns the input unchanged when not IPv4-mapped.
|
|---|
| 2598 | const IPV4_MAPPED_DOTTED_RE = /^(?:::|(?:0{1,4}:){1,4}:|(?:0{1,4}:){5})ffff:(\d+\.\d+\.\d+\.\d+)$/i;
|
|---|
| 2599 | const IPV4_MAPPED_HEX_RE = /^(?:::|(?:0{1,4}:){1,4}:|(?:0{1,4}:){5})ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i;
|
|---|
| 2600 | const unmapIPv4MappedIPv6 = host => {
|
|---|
| 2601 | if (typeof host !== 'string' || host.indexOf(':') === -1) return host;
|
|---|
| 2602 | const dotted = host.match(IPV4_MAPPED_DOTTED_RE);
|
|---|
| 2603 | if (dotted) return dotted[1];
|
|---|
| 2604 | const hex = host.match(IPV4_MAPPED_HEX_RE);
|
|---|
| 2605 | if (hex) {
|
|---|
| 2606 | const high = parseInt(hex[1], 16);
|
|---|
| 2607 | const low = parseInt(hex[2], 16);
|
|---|
| 2608 | return `${high >> 8}.${high & 0xff}.${low >> 8}.${low & 0xff}`;
|
|---|
| 2609 | }
|
|---|
| 2610 | return host;
|
|---|
| 2611 | };
|
|---|
| 2612 | const normalizeNoProxyHost = hostname => {
|
|---|
| 2613 | if (!hostname) {
|
|---|
| 2614 | return hostname;
|
|---|
| 2615 | }
|
|---|
| 2616 | if (hostname.charAt(0) === '[' && hostname.charAt(hostname.length - 1) === ']') {
|
|---|
| 2617 | hostname = hostname.slice(1, -1);
|
|---|
| 2618 | }
|
|---|
| 2619 | return unmapIPv4MappedIPv6(hostname.replace(/\.+$/, ''));
|
|---|
| 2620 | };
|
|---|
| 2621 | function shouldBypassProxy(location) {
|
|---|
| 2622 | let parsed;
|
|---|
| 2623 | try {
|
|---|
| 2624 | parsed = new URL(location);
|
|---|
| 2625 | } catch (_err) {
|
|---|
| 2626 | return false;
|
|---|
| 2627 | }
|
|---|
| 2628 | const noProxy = (process.env.no_proxy || process.env.NO_PROXY || '').toLowerCase();
|
|---|
| 2629 | if (!noProxy) {
|
|---|
| 2630 | return false;
|
|---|
| 2631 | }
|
|---|
| 2632 | if (noProxy === '*') {
|
|---|
| 2633 | return true;
|
|---|
| 2634 | }
|
|---|
| 2635 | const port = Number.parseInt(parsed.port, 10) || DEFAULT_PORTS[parsed.protocol.split(':', 1)[0]] || 0;
|
|---|
| 2636 | const hostname = normalizeNoProxyHost(parsed.hostname.toLowerCase());
|
|---|
| 2637 | return noProxy.split(/[\s,]+/).some(entry => {
|
|---|
| 2638 | if (!entry) {
|
|---|
| 2639 | return false;
|
|---|
| 2640 | }
|
|---|
| 2641 | let [entryHost, entryPort] = parseNoProxyEntry(entry);
|
|---|
| 2642 | entryHost = normalizeNoProxyHost(entryHost);
|
|---|
| 2643 | if (!entryHost) {
|
|---|
| 2644 | return false;
|
|---|
| 2645 | }
|
|---|
| 2646 | if (entryPort && entryPort !== port) {
|
|---|
| 2647 | return false;
|
|---|
| 2648 | }
|
|---|
| 2649 | if (entryHost.charAt(0) === '*') {
|
|---|
| 2650 | entryHost = entryHost.slice(1);
|
|---|
| 2651 | }
|
|---|
| 2652 | if (entryHost.charAt(0) === '.') {
|
|---|
| 2653 | return hostname.endsWith(entryHost);
|
|---|
| 2654 | }
|
|---|
| 2655 | return hostname === entryHost || isLoopback(hostname) && isLoopback(entryHost);
|
|---|
| 2656 | });
|
|---|
| 2657 | }
|
|---|
| 2658 |
|
|---|
| 2659 | /**
|
|---|
| 2660 | * Calculate data maxRate
|
|---|
| 2661 | * @param {Number} [samplesCount= 10]
|
|---|
| 2662 | * @param {Number} [min= 1000]
|
|---|
| 2663 | * @returns {Function}
|
|---|
| 2664 | */
|
|---|
| 2665 | function speedometer(samplesCount, min) {
|
|---|
| 2666 | samplesCount = samplesCount || 10;
|
|---|
| 2667 | const bytes = new Array(samplesCount);
|
|---|
| 2668 | const timestamps = new Array(samplesCount);
|
|---|
| 2669 | let head = 0;
|
|---|
| 2670 | let tail = 0;
|
|---|
| 2671 | let firstSampleTS;
|
|---|
| 2672 | min = min !== undefined ? min : 1000;
|
|---|
| 2673 | return function push(chunkLength) {
|
|---|
| 2674 | const now = Date.now();
|
|---|
| 2675 | const startedAt = timestamps[tail];
|
|---|
| 2676 | if (!firstSampleTS) {
|
|---|
| 2677 | firstSampleTS = now;
|
|---|
| 2678 | }
|
|---|
| 2679 | bytes[head] = chunkLength;
|
|---|
| 2680 | timestamps[head] = now;
|
|---|
| 2681 | let i = tail;
|
|---|
| 2682 | let bytesCount = 0;
|
|---|
| 2683 | while (i !== head) {
|
|---|
| 2684 | bytesCount += bytes[i++];
|
|---|
| 2685 | i = i % samplesCount;
|
|---|
| 2686 | }
|
|---|
| 2687 | head = (head + 1) % samplesCount;
|
|---|
| 2688 | if (head === tail) {
|
|---|
| 2689 | tail = (tail + 1) % samplesCount;
|
|---|
| 2690 | }
|
|---|
| 2691 | if (now - firstSampleTS < min) {
|
|---|
| 2692 | return;
|
|---|
| 2693 | }
|
|---|
| 2694 | const passed = startedAt && now - startedAt;
|
|---|
| 2695 | return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
|
|---|
| 2696 | };
|
|---|
| 2697 | }
|
|---|
| 2698 |
|
|---|
| 2699 | /**
|
|---|
| 2700 | * Throttle decorator
|
|---|
| 2701 | * @param {Function} fn
|
|---|
| 2702 | * @param {Number} freq
|
|---|
| 2703 | * @return {Function}
|
|---|
| 2704 | */
|
|---|
| 2705 | function throttle(fn, freq) {
|
|---|
| 2706 | let timestamp = 0;
|
|---|
| 2707 | let threshold = 1000 / freq;
|
|---|
| 2708 | let lastArgs;
|
|---|
| 2709 | let timer;
|
|---|
| 2710 | const invoke = (args, now = Date.now()) => {
|
|---|
| 2711 | timestamp = now;
|
|---|
| 2712 | lastArgs = null;
|
|---|
| 2713 | if (timer) {
|
|---|
| 2714 | clearTimeout(timer);
|
|---|
| 2715 | timer = null;
|
|---|
| 2716 | }
|
|---|
| 2717 | fn(...args);
|
|---|
| 2718 | };
|
|---|
| 2719 | const throttled = (...args) => {
|
|---|
| 2720 | const now = Date.now();
|
|---|
| 2721 | const passed = now - timestamp;
|
|---|
| 2722 | if (passed >= threshold) {
|
|---|
| 2723 | invoke(args, now);
|
|---|
| 2724 | } else {
|
|---|
| 2725 | lastArgs = args;
|
|---|
| 2726 | if (!timer) {
|
|---|
| 2727 | timer = setTimeout(() => {
|
|---|
| 2728 | timer = null;
|
|---|
| 2729 | invoke(lastArgs);
|
|---|
| 2730 | }, threshold - passed);
|
|---|
| 2731 | }
|
|---|
| 2732 | }
|
|---|
| 2733 | };
|
|---|
| 2734 | const flush = () => lastArgs && invoke(lastArgs);
|
|---|
| 2735 | return [throttled, flush];
|
|---|
| 2736 | }
|
|---|
| 2737 |
|
|---|
| 2738 | const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
|---|
| 2739 | let bytesNotified = 0;
|
|---|
| 2740 | const _speedometer = speedometer(50, 250);
|
|---|
| 2741 | return throttle(e => {
|
|---|
| 2742 | if (!e || typeof e.loaded !== 'number') {
|
|---|
| 2743 | return;
|
|---|
| 2744 | }
|
|---|
| 2745 | const rawLoaded = e.loaded;
|
|---|
| 2746 | const total = e.lengthComputable ? e.total : undefined;
|
|---|
| 2747 | const loaded = total != null ? Math.min(rawLoaded, total) : rawLoaded;
|
|---|
| 2748 | const progressBytes = Math.max(0, loaded - bytesNotified);
|
|---|
| 2749 | const rate = _speedometer(progressBytes);
|
|---|
| 2750 | bytesNotified = Math.max(bytesNotified, loaded);
|
|---|
| 2751 | const data = {
|
|---|
| 2752 | loaded,
|
|---|
| 2753 | total,
|
|---|
| 2754 | progress: total ? loaded / total : undefined,
|
|---|
| 2755 | bytes: progressBytes,
|
|---|
| 2756 | rate: rate ? rate : undefined,
|
|---|
| 2757 | estimated: rate && total ? (total - loaded) / rate : undefined,
|
|---|
| 2758 | event: e,
|
|---|
| 2759 | lengthComputable: total != null,
|
|---|
| 2760 | [isDownloadStream ? 'download' : 'upload']: true
|
|---|
| 2761 | };
|
|---|
| 2762 | listener(data);
|
|---|
| 2763 | }, freq);
|
|---|
| 2764 | };
|
|---|
| 2765 | const progressEventDecorator = (total, throttled) => {
|
|---|
| 2766 | const lengthComputable = total != null;
|
|---|
| 2767 | return [loaded => throttled[0]({
|
|---|
| 2768 | lengthComputable,
|
|---|
| 2769 | total,
|
|---|
| 2770 | loaded
|
|---|
| 2771 | }), throttled[1]];
|
|---|
| 2772 | };
|
|---|
| 2773 | const asyncDecorator = fn => (...args) => utils$1.asap(() => fn(...args));
|
|---|
| 2774 |
|
|---|
| 2775 | /**
|
|---|
| 2776 | * Estimate decoded byte length of a data:// URL *without* allocating large buffers.
|
|---|
| 2777 | * - For base64: compute exact decoded size using length and padding;
|
|---|
| 2778 | * handle %XX at the character-count level (no string allocation).
|
|---|
| 2779 | * - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.
|
|---|
| 2780 | *
|
|---|
| 2781 | * @param {string} url
|
|---|
| 2782 | * @returns {number}
|
|---|
| 2783 | */
|
|---|
| 2784 | function estimateDataURLDecodedBytes(url) {
|
|---|
| 2785 | if (!url || typeof url !== 'string') return 0;
|
|---|
| 2786 | if (!url.startsWith('data:')) return 0;
|
|---|
| 2787 | const comma = url.indexOf(',');
|
|---|
| 2788 | if (comma < 0) return 0;
|
|---|
| 2789 | const meta = url.slice(5, comma);
|
|---|
| 2790 | const body = url.slice(comma + 1);
|
|---|
| 2791 | const isBase64 = /;base64/i.test(meta);
|
|---|
| 2792 | if (isBase64) {
|
|---|
| 2793 | let effectiveLen = body.length;
|
|---|
| 2794 | const len = body.length; // cache length
|
|---|
| 2795 |
|
|---|
| 2796 | for (let i = 0; i < len; i++) {
|
|---|
| 2797 | if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
|
|---|
| 2798 | const a = body.charCodeAt(i + 1);
|
|---|
| 2799 | const b = body.charCodeAt(i + 2);
|
|---|
| 2800 | const isHex = (a >= 48 && a <= 57 || a >= 65 && a <= 70 || a >= 97 && a <= 102) && (b >= 48 && b <= 57 || b >= 65 && b <= 70 || b >= 97 && b <= 102);
|
|---|
| 2801 | if (isHex) {
|
|---|
| 2802 | effectiveLen -= 2;
|
|---|
| 2803 | i += 2;
|
|---|
| 2804 | }
|
|---|
| 2805 | }
|
|---|
| 2806 | }
|
|---|
| 2807 | let pad = 0;
|
|---|
| 2808 | let idx = len - 1;
|
|---|
| 2809 | const tailIsPct3D = j => j >= 2 && body.charCodeAt(j - 2) === 37 &&
|
|---|
| 2810 | // '%'
|
|---|
| 2811 | body.charCodeAt(j - 1) === 51 && (
|
|---|
| 2812 | // '3'
|
|---|
| 2813 | body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100); // 'D' or 'd'
|
|---|
| 2814 |
|
|---|
| 2815 | if (idx >= 0) {
|
|---|
| 2816 | if (body.charCodeAt(idx) === 61 /* '=' */) {
|
|---|
| 2817 | pad++;
|
|---|
| 2818 | idx--;
|
|---|
| 2819 | } else if (tailIsPct3D(idx)) {
|
|---|
| 2820 | pad++;
|
|---|
| 2821 | idx -= 3;
|
|---|
| 2822 | }
|
|---|
| 2823 | }
|
|---|
| 2824 | if (pad === 1 && idx >= 0) {
|
|---|
| 2825 | if (body.charCodeAt(idx) === 61 /* '=' */) {
|
|---|
| 2826 | pad++;
|
|---|
| 2827 | } else if (tailIsPct3D(idx)) {
|
|---|
| 2828 | pad++;
|
|---|
| 2829 | }
|
|---|
| 2830 | }
|
|---|
| 2831 | const groups = Math.floor(effectiveLen / 4);
|
|---|
| 2832 | const bytes = groups * 3 - (pad || 0);
|
|---|
| 2833 | return bytes > 0 ? bytes : 0;
|
|---|
| 2834 | }
|
|---|
| 2835 | if (typeof Buffer !== 'undefined' && typeof Buffer.byteLength === 'function') {
|
|---|
| 2836 | return Buffer.byteLength(body, 'utf8');
|
|---|
| 2837 | }
|
|---|
| 2838 |
|
|---|
| 2839 | // Compute UTF-8 byte length directly from UTF-16 code units without allocating
|
|---|
| 2840 | // a byte buffer (TextEncoder.encode would defeat the DoS guard on large bodies).
|
|---|
| 2841 | // Using body.length here would undercount non-ASCII (e.g. '€' is 1 code unit
|
|---|
| 2842 | // but 3 UTF-8 bytes).
|
|---|
| 2843 | let bytes = 0;
|
|---|
| 2844 | for (let i = 0, len = body.length; i < len; i++) {
|
|---|
| 2845 | const c = body.charCodeAt(i);
|
|---|
| 2846 | if (c < 0x80) {
|
|---|
| 2847 | bytes += 1;
|
|---|
| 2848 | } else if (c < 0x800) {
|
|---|
| 2849 | bytes += 2;
|
|---|
| 2850 | } else if (c >= 0xd800 && c <= 0xdbff && i + 1 < len) {
|
|---|
| 2851 | const next = body.charCodeAt(i + 1);
|
|---|
| 2852 | if (next >= 0xdc00 && next <= 0xdfff) {
|
|---|
| 2853 | bytes += 4;
|
|---|
| 2854 | i++;
|
|---|
| 2855 | } else {
|
|---|
| 2856 | bytes += 3;
|
|---|
| 2857 | }
|
|---|
| 2858 | } else {
|
|---|
| 2859 | bytes += 3;
|
|---|
| 2860 | }
|
|---|
| 2861 | }
|
|---|
| 2862 | return bytes;
|
|---|
| 2863 | }
|
|---|
| 2864 |
|
|---|
| 2865 | const zlibOptions = {
|
|---|
| 2866 | flush: zlib.constants.Z_SYNC_FLUSH,
|
|---|
| 2867 | finishFlush: zlib.constants.Z_SYNC_FLUSH
|
|---|
| 2868 | };
|
|---|
| 2869 | const brotliOptions = {
|
|---|
| 2870 | flush: zlib.constants.BROTLI_OPERATION_FLUSH,
|
|---|
| 2871 | finishFlush: zlib.constants.BROTLI_OPERATION_FLUSH
|
|---|
| 2872 | };
|
|---|
| 2873 | const isBrotliSupported = utils$1.isFunction(zlib.createBrotliDecompress);
|
|---|
| 2874 | const {
|
|---|
| 2875 | http: httpFollow,
|
|---|
| 2876 | https: httpsFollow
|
|---|
| 2877 | } = followRedirects;
|
|---|
| 2878 | const isHttps = /https:?/;
|
|---|
| 2879 | const FORM_DATA_CONTENT_HEADERS$1 = ['content-type', 'content-length'];
|
|---|
| 2880 | function setFormDataHeaders$1(headers, formHeaders, policy) {
|
|---|
| 2881 | if (policy !== 'content-only') {
|
|---|
| 2882 | headers.set(formHeaders);
|
|---|
| 2883 | return;
|
|---|
| 2884 | }
|
|---|
| 2885 | Object.entries(formHeaders).forEach(([key, val]) => {
|
|---|
| 2886 | if (FORM_DATA_CONTENT_HEADERS$1.includes(key.toLowerCase())) {
|
|---|
| 2887 | headers.set(key, val);
|
|---|
| 2888 | }
|
|---|
| 2889 | });
|
|---|
| 2890 | }
|
|---|
| 2891 |
|
|---|
| 2892 | // Symbols used to bind a single 'error' listener to a pooled socket and track
|
|---|
| 2893 | // the request currently owning that socket across keep-alive reuse (issue #10780).
|
|---|
| 2894 | const kAxiosSocketListener = Symbol('axios.http.socketListener');
|
|---|
| 2895 | const kAxiosCurrentReq = Symbol('axios.http.currentReq');
|
|---|
| 2896 |
|
|---|
| 2897 | // Tags HttpsProxyAgent instances installed by setProxy() so the redirect path
|
|---|
| 2898 | // can strip them without clobbering a user-supplied agent that happens to be
|
|---|
| 2899 | // an HttpsProxyAgent.
|
|---|
| 2900 | const kAxiosInstalledTunnel = Symbol('axios.http.installedTunnel');
|
|---|
| 2901 |
|
|---|
| 2902 | // Cache of CONNECT-tunneling agents keyed by proxy config so repeat requests
|
|---|
| 2903 | // through the same proxy reuse a single agent (and its socket pool). The
|
|---|
| 2904 | // keyspace is bounded by the set of distinct proxy configs the process uses,
|
|---|
| 2905 | // so unbounded growth is not a concern in practice.
|
|---|
| 2906 | const tunnelingAgentCache = new Map();
|
|---|
| 2907 | const tunnelingAgentCacheUser = new WeakMap();
|
|---|
| 2908 | function getTunnelingAgent(agentOptions, userHttpsAgent) {
|
|---|
| 2909 | const key = agentOptions.protocol + '//' + agentOptions.hostname + ':' + (agentOptions.port || '') + '#' + (agentOptions.auth || '');
|
|---|
| 2910 | const cache = userHttpsAgent ? tunnelingAgentCacheUser.get(userHttpsAgent) || tunnelingAgentCacheUser.set(userHttpsAgent, new Map()).get(userHttpsAgent) : tunnelingAgentCache;
|
|---|
| 2911 | let agent = cache.get(key);
|
|---|
| 2912 | if (agent) return agent;
|
|---|
| 2913 | // Forward the user's TLS options (custom CA, rejectUnauthorized, client cert,
|
|---|
| 2914 | // etc.) into the tunneling agent so they apply to the origin TLS upgrade
|
|---|
| 2915 | // performed after CONNECT. Our proxy fields take precedence on conflict.
|
|---|
| 2916 | const merged = userHttpsAgent && userHttpsAgent.options ? {
|
|---|
| 2917 | ...userHttpsAgent.options,
|
|---|
| 2918 | ...agentOptions
|
|---|
| 2919 | } : agentOptions;
|
|---|
| 2920 | agent = new HttpsProxyAgent(merged);
|
|---|
| 2921 | agent[kAxiosInstalledTunnel] = true;
|
|---|
| 2922 | cache.set(key, agent);
|
|---|
| 2923 | return agent;
|
|---|
| 2924 | }
|
|---|
| 2925 | const supportedProtocols = platform.protocols.map(protocol => {
|
|---|
| 2926 | return protocol + ':';
|
|---|
| 2927 | });
|
|---|
| 2928 |
|
|---|
| 2929 | // Node's WHATWG URL parser returns `username` and `password` percent-encoded.
|
|---|
| 2930 | // Decode before composing the `auth` option so credentials such as
|
|---|
| 2931 | // `my%40email.com:pass` are sent as `my@email.com:pass`. Falls back to the
|
|---|
| 2932 | // original value for malformed input so a bad encoding never throws.
|
|---|
| 2933 | const decodeURIComponentSafe = value => {
|
|---|
| 2934 | if (!utils$1.isString(value)) {
|
|---|
| 2935 | return value;
|
|---|
| 2936 | }
|
|---|
| 2937 | try {
|
|---|
| 2938 | return decodeURIComponent(value);
|
|---|
| 2939 | } catch (error) {
|
|---|
| 2940 | return value;
|
|---|
| 2941 | }
|
|---|
| 2942 | };
|
|---|
| 2943 | const flushOnFinish = (stream, [throttled, flush]) => {
|
|---|
| 2944 | stream.on('end', flush).on('error', flush);
|
|---|
| 2945 | return throttled;
|
|---|
| 2946 | };
|
|---|
| 2947 | class Http2Sessions {
|
|---|
| 2948 | constructor() {
|
|---|
| 2949 | this.sessions = Object.create(null);
|
|---|
| 2950 | }
|
|---|
| 2951 | getSession(authority, options) {
|
|---|
| 2952 | options = Object.assign({
|
|---|
| 2953 | sessionTimeout: 1000
|
|---|
| 2954 | }, options);
|
|---|
| 2955 | let authoritySessions = this.sessions[authority];
|
|---|
| 2956 | if (authoritySessions) {
|
|---|
| 2957 | let len = authoritySessions.length;
|
|---|
| 2958 | for (let i = 0; i < len; i++) {
|
|---|
| 2959 | const [sessionHandle, sessionOptions] = authoritySessions[i];
|
|---|
| 2960 | if (!sessionHandle.destroyed && !sessionHandle.closed && util.isDeepStrictEqual(sessionOptions, options)) {
|
|---|
| 2961 | return sessionHandle;
|
|---|
| 2962 | }
|
|---|
| 2963 | }
|
|---|
| 2964 | }
|
|---|
| 2965 | const session = http2.connect(authority, options);
|
|---|
| 2966 | let removed;
|
|---|
| 2967 | const removeSession = () => {
|
|---|
| 2968 | if (removed) {
|
|---|
| 2969 | return;
|
|---|
| 2970 | }
|
|---|
| 2971 | removed = true;
|
|---|
| 2972 | let entries = authoritySessions,
|
|---|
| 2973 | len = entries.length,
|
|---|
| 2974 | i = len;
|
|---|
| 2975 | while (i--) {
|
|---|
| 2976 | if (entries[i][0] === session) {
|
|---|
| 2977 | if (len === 1) {
|
|---|
| 2978 | delete this.sessions[authority];
|
|---|
| 2979 | } else {
|
|---|
| 2980 | entries.splice(i, 1);
|
|---|
| 2981 | }
|
|---|
| 2982 | if (!session.closed) {
|
|---|
| 2983 | session.close();
|
|---|
| 2984 | }
|
|---|
| 2985 | return;
|
|---|
| 2986 | }
|
|---|
| 2987 | }
|
|---|
| 2988 | };
|
|---|
| 2989 | const originalRequestFn = session.request;
|
|---|
| 2990 | const {
|
|---|
| 2991 | sessionTimeout
|
|---|
| 2992 | } = options;
|
|---|
| 2993 | if (sessionTimeout != null) {
|
|---|
| 2994 | let timer;
|
|---|
| 2995 | let streamsCount = 0;
|
|---|
| 2996 | session.request = function () {
|
|---|
| 2997 | const stream = originalRequestFn.apply(this, arguments);
|
|---|
| 2998 | streamsCount++;
|
|---|
| 2999 | if (timer) {
|
|---|
| 3000 | clearTimeout(timer);
|
|---|
| 3001 | timer = null;
|
|---|
| 3002 | }
|
|---|
| 3003 | stream.once('close', () => {
|
|---|
| 3004 | if (! --streamsCount) {
|
|---|
| 3005 | timer = setTimeout(() => {
|
|---|
| 3006 | timer = null;
|
|---|
| 3007 | removeSession();
|
|---|
| 3008 | }, sessionTimeout);
|
|---|
| 3009 | }
|
|---|
| 3010 | });
|
|---|
| 3011 | return stream;
|
|---|
| 3012 | };
|
|---|
| 3013 | }
|
|---|
| 3014 | session.once('close', removeSession);
|
|---|
| 3015 | let entry = [session, options];
|
|---|
| 3016 | authoritySessions ? authoritySessions.push(entry) : authoritySessions = this.sessions[authority] = [entry];
|
|---|
| 3017 | return session;
|
|---|
| 3018 | }
|
|---|
| 3019 | }
|
|---|
| 3020 | const http2Sessions = new Http2Sessions();
|
|---|
| 3021 |
|
|---|
| 3022 | /**
|
|---|
| 3023 | * If the proxy or config beforeRedirects functions are defined, call them with the options
|
|---|
| 3024 | * object.
|
|---|
| 3025 | *
|
|---|
| 3026 | * @param {Object<string, any>} options - The options object that was passed to the request.
|
|---|
| 3027 | *
|
|---|
| 3028 | * @returns {Object<string, any>}
|
|---|
| 3029 | */
|
|---|
| 3030 | function dispatchBeforeRedirect(options, responseDetails, requestDetails) {
|
|---|
| 3031 | if (options.beforeRedirects.proxy) {
|
|---|
| 3032 | options.beforeRedirects.proxy(options);
|
|---|
| 3033 | }
|
|---|
| 3034 | if (options.beforeRedirects.config) {
|
|---|
| 3035 | options.beforeRedirects.config(options, responseDetails, requestDetails);
|
|---|
| 3036 | }
|
|---|
| 3037 | }
|
|---|
| 3038 |
|
|---|
| 3039 | /**
|
|---|
| 3040 | * If the proxy or config afterRedirects functions are defined, call them with the options
|
|---|
| 3041 | *
|
|---|
| 3042 | * @param {http.ClientRequestArgs} options
|
|---|
| 3043 | * @param {AxiosProxyConfig} configProxy configuration from Axios options object
|
|---|
| 3044 | * @param {string} location
|
|---|
| 3045 | *
|
|---|
| 3046 | * @returns {http.ClientRequestArgs}
|
|---|
| 3047 | */
|
|---|
| 3048 | function setProxy(options, configProxy, location, isRedirect, configHttpsAgent) {
|
|---|
| 3049 | let proxy = configProxy;
|
|---|
| 3050 | if (!proxy && proxy !== false) {
|
|---|
| 3051 | const proxyUrl = getProxyForUrl(location);
|
|---|
| 3052 | if (proxyUrl) {
|
|---|
| 3053 | if (!shouldBypassProxy(location)) {
|
|---|
| 3054 | proxy = new URL(proxyUrl);
|
|---|
| 3055 | }
|
|---|
| 3056 | }
|
|---|
| 3057 | }
|
|---|
| 3058 | // On redirect re-invocation, strip any stale Proxy-Authorization header carried
|
|---|
| 3059 | // over from the prior request (e.g. new target no longer uses a proxy, or uses
|
|---|
| 3060 | // a different proxy). Skip on the initial request so user-supplied headers are
|
|---|
| 3061 | // preserved. Header names are case-insensitive, so remove every case variant.
|
|---|
| 3062 | if (isRedirect && options.headers) {
|
|---|
| 3063 | for (const name of Object.keys(options.headers)) {
|
|---|
| 3064 | if (name.toLowerCase() === 'proxy-authorization') {
|
|---|
| 3065 | delete options.headers[name];
|
|---|
| 3066 | }
|
|---|
| 3067 | }
|
|---|
| 3068 | }
|
|---|
| 3069 | // Strip any tunneling agent we installed for the previous hop so a redirect
|
|---|
| 3070 | // that drops the proxy or crosses an HTTPS↔HTTP boundary doesn't reuse a
|
|---|
| 3071 | // stale one. Match on our Symbol marker so a user-supplied HttpsProxyAgent
|
|---|
| 3072 | // (which won't carry the marker) is left alone.
|
|---|
| 3073 | if (isRedirect && options.agent && options.agent[kAxiosInstalledTunnel]) {
|
|---|
| 3074 | options.agent = undefined;
|
|---|
| 3075 | }
|
|---|
| 3076 | if (proxy) {
|
|---|
| 3077 | // Read proxy fields without traversing the prototype chain. URL instances expose
|
|---|
| 3078 | // username/password/hostname/host/port/protocol via getters on URL.prototype (so
|
|---|
| 3079 | // direct reads are shielded), but plain object proxies — and the `auth` field
|
|---|
| 3080 | // (which URL does not expose) — must be guarded so a polluted Object.prototype
|
|---|
| 3081 | // (e.g. Object.prototype.auth = { username, password }) cannot inject
|
|---|
| 3082 | // attacker-controlled credentials into the Proxy-Authorization header or
|
|---|
| 3083 | // redirect proxying to an attacker-controlled host.
|
|---|
| 3084 | const isProxyURL = proxy instanceof URL;
|
|---|
| 3085 | const readProxyField = key => isProxyURL || utils$1.hasOwnProp(proxy, key) ? proxy[key] : undefined;
|
|---|
| 3086 | const proxyUsername = readProxyField('username');
|
|---|
| 3087 | const proxyPassword = readProxyField('password');
|
|---|
| 3088 | let proxyAuth = utils$1.hasOwnProp(proxy, 'auth') ? proxy.auth : undefined;
|
|---|
| 3089 |
|
|---|
| 3090 | // Basic proxy authorization
|
|---|
| 3091 | if (proxyUsername) {
|
|---|
| 3092 | proxyAuth = (proxyUsername || '') + ':' + (proxyPassword || '');
|
|---|
| 3093 | }
|
|---|
| 3094 | if (proxyAuth) {
|
|---|
| 3095 | // Support proxy auth object form. Read sub-fields via own-prop checks so a
|
|---|
| 3096 | // plain object inheriting from polluted Object.prototype cannot leak creds.
|
|---|
| 3097 | const authIsObject = typeof proxyAuth === 'object';
|
|---|
| 3098 | const authUsername = authIsObject && utils$1.hasOwnProp(proxyAuth, 'username') ? proxyAuth.username : undefined;
|
|---|
| 3099 | const authPassword = authIsObject && utils$1.hasOwnProp(proxyAuth, 'password') ? proxyAuth.password : undefined;
|
|---|
| 3100 | const validProxyAuth = Boolean(authUsername || authPassword);
|
|---|
| 3101 | if (validProxyAuth) {
|
|---|
| 3102 | proxyAuth = (authUsername || '') + ':' + (authPassword || '');
|
|---|
| 3103 | } else if (authIsObject) {
|
|---|
| 3104 | throw new AxiosError('Invalid proxy authorization', AxiosError.ERR_BAD_OPTION, {
|
|---|
| 3105 | proxy
|
|---|
| 3106 | });
|
|---|
| 3107 | }
|
|---|
| 3108 | }
|
|---|
| 3109 | const targetIsHttps = isHttps.test(options.protocol);
|
|---|
| 3110 | if (targetIsHttps) {
|
|---|
| 3111 | // CONNECT-tunneling path for HTTPS targets. Preserves end-to-end TLS to
|
|---|
| 3112 | // the origin so the proxy cannot inspect the URL, headers, or body — the
|
|---|
| 3113 | // behavior already promised by THREATMODEL.md (T-R9). HttpsProxyAgent
|
|---|
| 3114 | // sends Proxy-Authorization on the CONNECT request only, never on the
|
|---|
| 3115 | // wrapped TLS request, which is why we don't stamp it onto
|
|---|
| 3116 | // options.headers here. If the user already supplied an HttpsProxyAgent,
|
|---|
| 3117 | // they own tunneling end-to-end and we leave them alone; otherwise we
|
|---|
| 3118 | // install our own tunneling agent and forward their TLS options (if any)
|
|---|
| 3119 | // so a custom httpsAgent for cert pinning / rejectUnauthorized still
|
|---|
| 3120 | // applies to the origin TLS upgrade.
|
|---|
| 3121 | if (!(configHttpsAgent instanceof HttpsProxyAgent)) {
|
|---|
| 3122 | const proxyHost = readProxyField('hostname') || readProxyField('host');
|
|---|
| 3123 | const proxyPort = readProxyField('port');
|
|---|
| 3124 | const rawProxyProtocol = readProxyField('protocol');
|
|---|
| 3125 | const normalizedProtocol = rawProxyProtocol ? rawProxyProtocol.includes(':') ? rawProxyProtocol : `${rawProxyProtocol}:` : 'http:';
|
|---|
| 3126 | // Bracket IPv6 literals for URL parsing; URL.hostname strips the
|
|---|
| 3127 | // brackets again on read so the agent receives the raw form.
|
|---|
| 3128 | const proxyHostForURL = proxyHost && proxyHost.includes(':') && !proxyHost.startsWith('[') ? `[${proxyHost}]` : proxyHost;
|
|---|
| 3129 | const proxyURL = new URL(`${normalizedProtocol}//${proxyHostForURL}${proxyPort ? ':' + proxyPort : ''}`);
|
|---|
| 3130 | const agentOptions = {
|
|---|
| 3131 | protocol: proxyURL.protocol,
|
|---|
| 3132 | hostname: proxyURL.hostname.replace(/^\[|\]$/g, ''),
|
|---|
| 3133 | port: proxyURL.port,
|
|---|
| 3134 | auth: proxyAuth && typeof proxyAuth === 'string' ? proxyAuth : undefined
|
|---|
| 3135 | };
|
|---|
| 3136 | if (proxyURL.protocol === 'https:') {
|
|---|
| 3137 | agentOptions.ALPNProtocols = ['http/1.1'];
|
|---|
| 3138 | }
|
|---|
| 3139 | const tunnelingAgent = getTunnelingAgent(agentOptions, configHttpsAgent);
|
|---|
| 3140 | // Set both: `options.agent` is consumed by the native https.request path
|
|---|
| 3141 | // (config.maxRedirects === 0); `options.agents.https` is consumed by
|
|---|
| 3142 | // follow-redirects, which ignores `options.agent` when `options.agents`
|
|---|
| 3143 | // is present.
|
|---|
| 3144 | options.agent = tunnelingAgent;
|
|---|
| 3145 | if (options.agents) {
|
|---|
| 3146 | options.agents.https = tunnelingAgent;
|
|---|
| 3147 | }
|
|---|
| 3148 | }
|
|---|
| 3149 | } else {
|
|---|
| 3150 | // Forward-proxy mode for plaintext HTTP targets. The request line carries
|
|---|
| 3151 | // the absolute URL and the proxy sees everything — acceptable for plain
|
|---|
| 3152 | // HTTP since the wire was already plaintext.
|
|---|
| 3153 | if (proxyAuth) {
|
|---|
| 3154 | const base64 = Buffer.from(proxyAuth, 'utf8').toString('base64');
|
|---|
| 3155 | options.headers['Proxy-Authorization'] = 'Basic ' + base64;
|
|---|
| 3156 | }
|
|---|
| 3157 |
|
|---|
| 3158 | // Preserve a user-supplied Host header (case-insensitive) so callers can override
|
|---|
| 3159 | // the value forwarded to the proxy; otherwise default to the request URL's host.
|
|---|
| 3160 | let hasUserHostHeader = false;
|
|---|
| 3161 | for (const name of Object.keys(options.headers)) {
|
|---|
| 3162 | if (name.toLowerCase() === 'host') {
|
|---|
| 3163 | hasUserHostHeader = true;
|
|---|
| 3164 | break;
|
|---|
| 3165 | }
|
|---|
| 3166 | }
|
|---|
| 3167 | if (!hasUserHostHeader) {
|
|---|
| 3168 | options.headers.host = options.hostname + (options.port ? ':' + options.port : '');
|
|---|
| 3169 | }
|
|---|
| 3170 | const proxyHost = readProxyField('hostname') || readProxyField('host');
|
|---|
| 3171 | options.hostname = proxyHost;
|
|---|
| 3172 | // Replace 'host' since options is not a URL object
|
|---|
| 3173 | options.host = proxyHost;
|
|---|
| 3174 | options.port = readProxyField('port');
|
|---|
| 3175 | options.path = location;
|
|---|
| 3176 | const proxyProtocol = readProxyField('protocol');
|
|---|
| 3177 | if (proxyProtocol) {
|
|---|
| 3178 | options.protocol = proxyProtocol.includes(':') ? proxyProtocol : `${proxyProtocol}:`;
|
|---|
| 3179 | }
|
|---|
| 3180 | }
|
|---|
| 3181 | }
|
|---|
| 3182 | options.beforeRedirects.proxy = function beforeRedirect(redirectOptions) {
|
|---|
| 3183 | // Configure proxy for redirected request, passing the original config proxy to apply
|
|---|
| 3184 | // the exact same logic as if the redirected request was performed by axios directly.
|
|---|
| 3185 | setProxy(redirectOptions, configProxy, redirectOptions.href, true, configHttpsAgent);
|
|---|
| 3186 | };
|
|---|
| 3187 | }
|
|---|
| 3188 | const isHttpAdapterSupported = typeof process !== 'undefined' && utils$1.kindOf(process) === 'process';
|
|---|
| 3189 |
|
|---|
| 3190 | // temporary hotfix
|
|---|
| 3191 |
|
|---|
| 3192 | const wrapAsync = asyncExecutor => {
|
|---|
| 3193 | return new Promise((resolve, reject) => {
|
|---|
| 3194 | let onDone;
|
|---|
| 3195 | let isDone;
|
|---|
| 3196 | const done = (value, isRejected) => {
|
|---|
| 3197 | if (isDone) return;
|
|---|
| 3198 | isDone = true;
|
|---|
| 3199 | onDone && onDone(value, isRejected);
|
|---|
| 3200 | };
|
|---|
| 3201 | const _resolve = value => {
|
|---|
| 3202 | done(value);
|
|---|
| 3203 | resolve(value);
|
|---|
| 3204 | };
|
|---|
| 3205 | const _reject = reason => {
|
|---|
| 3206 | done(reason, true);
|
|---|
| 3207 | reject(reason);
|
|---|
| 3208 | };
|
|---|
| 3209 | asyncExecutor(_resolve, _reject, onDoneHandler => onDone = onDoneHandler).catch(_reject);
|
|---|
| 3210 | });
|
|---|
| 3211 | };
|
|---|
| 3212 | const resolveFamily = ({
|
|---|
| 3213 | address,
|
|---|
| 3214 | family
|
|---|
| 3215 | }) => {
|
|---|
| 3216 | if (!utils$1.isString(address)) {
|
|---|
| 3217 | throw TypeError('address must be a string');
|
|---|
| 3218 | }
|
|---|
| 3219 | return {
|
|---|
| 3220 | address,
|
|---|
| 3221 | family: family || (address.indexOf('.') < 0 ? 6 : 4)
|
|---|
| 3222 | };
|
|---|
| 3223 | };
|
|---|
| 3224 | const buildAddressEntry = (address, family) => resolveFamily(utils$1.isObject(address) ? address : {
|
|---|
| 3225 | address,
|
|---|
| 3226 | family
|
|---|
| 3227 | });
|
|---|
| 3228 | const http2Transport = {
|
|---|
| 3229 | request(options, cb) {
|
|---|
| 3230 | const authority = options.protocol + '//' + options.hostname + ':' + (options.port || (options.protocol === 'https:' ? 443 : 80));
|
|---|
| 3231 | const {
|
|---|
| 3232 | http2Options,
|
|---|
| 3233 | headers
|
|---|
| 3234 | } = options;
|
|---|
| 3235 | const session = http2Sessions.getSession(authority, http2Options);
|
|---|
| 3236 | const {
|
|---|
| 3237 | HTTP2_HEADER_SCHEME,
|
|---|
| 3238 | HTTP2_HEADER_METHOD,
|
|---|
| 3239 | HTTP2_HEADER_PATH,
|
|---|
| 3240 | HTTP2_HEADER_STATUS
|
|---|
| 3241 | } = http2.constants;
|
|---|
| 3242 | const http2Headers = {
|
|---|
| 3243 | [HTTP2_HEADER_SCHEME]: options.protocol.replace(':', ''),
|
|---|
| 3244 | [HTTP2_HEADER_METHOD]: options.method,
|
|---|
| 3245 | [HTTP2_HEADER_PATH]: options.path
|
|---|
| 3246 | };
|
|---|
| 3247 | utils$1.forEach(headers, (header, name) => {
|
|---|
| 3248 | name.charAt(0) !== ':' && (http2Headers[name] = header);
|
|---|
| 3249 | });
|
|---|
| 3250 | const req = session.request(http2Headers);
|
|---|
| 3251 | req.once('response', responseHeaders => {
|
|---|
| 3252 | const response = req; //duplex
|
|---|
| 3253 |
|
|---|
| 3254 | responseHeaders = Object.assign({}, responseHeaders);
|
|---|
| 3255 | const status = responseHeaders[HTTP2_HEADER_STATUS];
|
|---|
| 3256 | delete responseHeaders[HTTP2_HEADER_STATUS];
|
|---|
| 3257 | response.headers = responseHeaders;
|
|---|
| 3258 | response.statusCode = +status;
|
|---|
| 3259 | cb(response);
|
|---|
| 3260 | });
|
|---|
| 3261 | return req;
|
|---|
| 3262 | }
|
|---|
| 3263 | };
|
|---|
| 3264 |
|
|---|
| 3265 | /*eslint consistent-return:0*/
|
|---|
| 3266 | var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|---|
| 3267 | return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
|
|---|
| 3268 | const own = key => utils$1.hasOwnProp(config, key) ? config[key] : undefined;
|
|---|
| 3269 | let data = own('data');
|
|---|
| 3270 | let lookup = own('lookup');
|
|---|
| 3271 | let family = own('family');
|
|---|
| 3272 | let httpVersion = own('httpVersion');
|
|---|
| 3273 | if (httpVersion === undefined) httpVersion = 1;
|
|---|
| 3274 | let http2Options = own('http2Options');
|
|---|
| 3275 | const responseType = own('responseType');
|
|---|
| 3276 | const responseEncoding = own('responseEncoding');
|
|---|
| 3277 | const method = config.method.toUpperCase();
|
|---|
| 3278 | let isDone;
|
|---|
| 3279 | let rejected = false;
|
|---|
| 3280 | let req;
|
|---|
| 3281 | let connectPhaseTimer;
|
|---|
| 3282 | httpVersion = +httpVersion;
|
|---|
| 3283 | if (Number.isNaN(httpVersion)) {
|
|---|
| 3284 | throw TypeError(`Invalid protocol version: '${config.httpVersion}' is not a number`);
|
|---|
| 3285 | }
|
|---|
| 3286 | if (httpVersion !== 1 && httpVersion !== 2) {
|
|---|
| 3287 | throw TypeError(`Unsupported protocol version '${httpVersion}'`);
|
|---|
| 3288 | }
|
|---|
| 3289 | const isHttp2 = httpVersion === 2;
|
|---|
| 3290 | if (lookup) {
|
|---|
| 3291 | const _lookup = callbackify(lookup, value => utils$1.isArray(value) ? value : [value]);
|
|---|
| 3292 | // hotfix to support opt.all option which is required for node 20.x
|
|---|
| 3293 | lookup = (hostname, opt, cb) => {
|
|---|
| 3294 | _lookup(hostname, opt, (err, arg0, arg1) => {
|
|---|
| 3295 | if (err) {
|
|---|
| 3296 | return cb(err);
|
|---|
| 3297 | }
|
|---|
| 3298 | const addresses = utils$1.isArray(arg0) ? arg0.map(addr => buildAddressEntry(addr)) : [buildAddressEntry(arg0, arg1)];
|
|---|
| 3299 | opt.all ? cb(err, addresses) : cb(err, addresses[0].address, addresses[0].family);
|
|---|
| 3300 | });
|
|---|
| 3301 | };
|
|---|
| 3302 | }
|
|---|
| 3303 | const abortEmitter = new events.EventEmitter();
|
|---|
| 3304 | function abort(reason) {
|
|---|
| 3305 | try {
|
|---|
| 3306 | abortEmitter.emit('abort', !reason || reason.type ? new CanceledError(null, config, req) : reason);
|
|---|
| 3307 | } catch (err) {
|
|---|
| 3308 | console.warn('emit error', err);
|
|---|
| 3309 | }
|
|---|
| 3310 | }
|
|---|
| 3311 | function clearConnectPhaseTimer() {
|
|---|
| 3312 | if (connectPhaseTimer) {
|
|---|
| 3313 | clearTimeout(connectPhaseTimer);
|
|---|
| 3314 | connectPhaseTimer = null;
|
|---|
| 3315 | }
|
|---|
| 3316 | }
|
|---|
| 3317 | function createTimeoutError() {
|
|---|
| 3318 | let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
|
|---|
| 3319 | const transitional = config.transitional || transitionalDefaults;
|
|---|
| 3320 | if (config.timeoutErrorMessage) {
|
|---|
| 3321 | timeoutErrorMessage = config.timeoutErrorMessage;
|
|---|
| 3322 | }
|
|---|
| 3323 | return new AxiosError(timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, config, req);
|
|---|
| 3324 | }
|
|---|
| 3325 | abortEmitter.once('abort', reject);
|
|---|
| 3326 | const onFinished = () => {
|
|---|
| 3327 | clearConnectPhaseTimer();
|
|---|
| 3328 | if (config.cancelToken) {
|
|---|
| 3329 | config.cancelToken.unsubscribe(abort);
|
|---|
| 3330 | }
|
|---|
| 3331 | if (config.signal) {
|
|---|
| 3332 | config.signal.removeEventListener('abort', abort);
|
|---|
| 3333 | }
|
|---|
| 3334 | abortEmitter.removeAllListeners();
|
|---|
| 3335 | };
|
|---|
| 3336 | if (config.cancelToken || config.signal) {
|
|---|
| 3337 | config.cancelToken && config.cancelToken.subscribe(abort);
|
|---|
| 3338 | if (config.signal) {
|
|---|
| 3339 | config.signal.aborted ? abort() : config.signal.addEventListener('abort', abort);
|
|---|
| 3340 | }
|
|---|
| 3341 | }
|
|---|
| 3342 | onDone((response, isRejected) => {
|
|---|
| 3343 | isDone = true;
|
|---|
| 3344 | clearConnectPhaseTimer();
|
|---|
| 3345 | if (isRejected) {
|
|---|
| 3346 | rejected = true;
|
|---|
| 3347 | onFinished();
|
|---|
| 3348 | return;
|
|---|
| 3349 | }
|
|---|
| 3350 | const {
|
|---|
| 3351 | data
|
|---|
| 3352 | } = response;
|
|---|
| 3353 | if (data instanceof stream.Readable || data instanceof stream.Duplex) {
|
|---|
| 3354 | const offListeners = stream.finished(data, () => {
|
|---|
| 3355 | offListeners();
|
|---|
| 3356 | onFinished();
|
|---|
| 3357 | });
|
|---|
| 3358 | } else {
|
|---|
| 3359 | onFinished();
|
|---|
| 3360 | }
|
|---|
| 3361 | });
|
|---|
| 3362 |
|
|---|
| 3363 | // Parse url
|
|---|
| 3364 | const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
|
|---|
| 3365 | const parsed = new URL(fullPath, platform.hasBrowserEnv ? platform.origin : undefined);
|
|---|
| 3366 | const protocol = parsed.protocol || supportedProtocols[0];
|
|---|
| 3367 | if (protocol === 'data:') {
|
|---|
| 3368 | // Apply the same semantics as HTTP: only enforce if a finite, non-negative cap is set.
|
|---|
| 3369 | if (config.maxContentLength > -1) {
|
|---|
| 3370 | // Use the exact string passed to fromDataURI (config.url); fall back to fullPath if needed.
|
|---|
| 3371 | const dataUrl = String(config.url || fullPath || '');
|
|---|
| 3372 | const estimated = estimateDataURLDecodedBytes(dataUrl);
|
|---|
| 3373 | if (estimated > config.maxContentLength) {
|
|---|
| 3374 | return reject(new AxiosError('maxContentLength size of ' + config.maxContentLength + ' exceeded', AxiosError.ERR_BAD_RESPONSE, config));
|
|---|
| 3375 | }
|
|---|
| 3376 | }
|
|---|
| 3377 | let convertedData;
|
|---|
| 3378 | if (method !== 'GET') {
|
|---|
| 3379 | return settle(resolve, reject, {
|
|---|
| 3380 | status: 405,
|
|---|
| 3381 | statusText: 'method not allowed',
|
|---|
| 3382 | headers: {},
|
|---|
| 3383 | config
|
|---|
| 3384 | });
|
|---|
| 3385 | }
|
|---|
| 3386 | try {
|
|---|
| 3387 | convertedData = fromDataURI(config.url, responseType === 'blob', {
|
|---|
| 3388 | Blob: config.env && config.env.Blob
|
|---|
| 3389 | });
|
|---|
| 3390 | } catch (err) {
|
|---|
| 3391 | throw AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config);
|
|---|
| 3392 | }
|
|---|
| 3393 | if (responseType === 'text') {
|
|---|
| 3394 | convertedData = convertedData.toString(responseEncoding);
|
|---|
| 3395 | if (!responseEncoding || responseEncoding === 'utf8') {
|
|---|
| 3396 | convertedData = utils$1.stripBOM(convertedData);
|
|---|
| 3397 | }
|
|---|
| 3398 | } else if (responseType === 'stream') {
|
|---|
| 3399 | convertedData = stream.Readable.from(convertedData);
|
|---|
| 3400 | }
|
|---|
| 3401 | return settle(resolve, reject, {
|
|---|
| 3402 | data: convertedData,
|
|---|
| 3403 | status: 200,
|
|---|
| 3404 | statusText: 'OK',
|
|---|
| 3405 | headers: new AxiosHeaders(),
|
|---|
| 3406 | config
|
|---|
| 3407 | });
|
|---|
| 3408 | }
|
|---|
| 3409 | if (supportedProtocols.indexOf(protocol) === -1) {
|
|---|
| 3410 | return reject(new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_BAD_REQUEST, config));
|
|---|
| 3411 | }
|
|---|
| 3412 | const headers = AxiosHeaders.from(config.headers).normalize();
|
|---|
| 3413 |
|
|---|
| 3414 | // Set User-Agent (required by some servers)
|
|---|
| 3415 | // See https://github.com/axios/axios/issues/69
|
|---|
| 3416 | // User-Agent is specified; handle case where no UA header is desired
|
|---|
| 3417 | // Only set header if it hasn't been set in config
|
|---|
| 3418 | headers.set('User-Agent', 'axios/' + VERSION, false);
|
|---|
| 3419 | const {
|
|---|
| 3420 | onUploadProgress,
|
|---|
| 3421 | onDownloadProgress
|
|---|
| 3422 | } = config;
|
|---|
| 3423 | const maxRate = config.maxRate;
|
|---|
| 3424 | let maxUploadRate = undefined;
|
|---|
| 3425 | let maxDownloadRate = undefined;
|
|---|
| 3426 |
|
|---|
| 3427 | // support for spec compliant FormData objects
|
|---|
| 3428 | if (utils$1.isSpecCompliantForm(data)) {
|
|---|
| 3429 | const userBoundary = headers.getContentType(/boundary=([-_\w\d]{10,70})/i);
|
|---|
| 3430 | data = formDataToStream(data, formHeaders => {
|
|---|
| 3431 | headers.set(formHeaders);
|
|---|
| 3432 | }, {
|
|---|
| 3433 | tag: `axios-${VERSION}-boundary`,
|
|---|
| 3434 | boundary: userBoundary && userBoundary[1] || undefined
|
|---|
| 3435 | });
|
|---|
| 3436 | // support for https://www.npmjs.com/package/form-data api
|
|---|
| 3437 | } else if (utils$1.isFormData(data) && utils$1.isFunction(data.getHeaders) && data.getHeaders !== Object.prototype.getHeaders) {
|
|---|
| 3438 | setFormDataHeaders$1(headers, data.getHeaders(), own('formDataHeaderPolicy'));
|
|---|
| 3439 | if (!headers.hasContentLength()) {
|
|---|
| 3440 | try {
|
|---|
| 3441 | const knownLength = await util.promisify(data.getLength).call(data);
|
|---|
| 3442 | Number.isFinite(knownLength) && knownLength >= 0 && headers.setContentLength(knownLength);
|
|---|
| 3443 | /*eslint no-empty:0*/
|
|---|
| 3444 | } catch (e) {}
|
|---|
| 3445 | }
|
|---|
| 3446 | } else if (utils$1.isBlob(data) || utils$1.isFile(data)) {
|
|---|
| 3447 | data.size && headers.setContentType(data.type || 'application/octet-stream');
|
|---|
| 3448 | headers.setContentLength(data.size || 0);
|
|---|
| 3449 | data = stream.Readable.from(readBlob(data));
|
|---|
| 3450 | } else if (data && !utils$1.isStream(data)) {
|
|---|
| 3451 | if (Buffer.isBuffer(data)) ; else if (utils$1.isArrayBuffer(data)) {
|
|---|
| 3452 | data = Buffer.from(new Uint8Array(data));
|
|---|
| 3453 | } else if (utils$1.isString(data)) {
|
|---|
| 3454 | data = Buffer.from(data, 'utf-8');
|
|---|
| 3455 | } else {
|
|---|
| 3456 | return reject(new AxiosError('Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream', AxiosError.ERR_BAD_REQUEST, config));
|
|---|
| 3457 | }
|
|---|
| 3458 |
|
|---|
| 3459 | // Add Content-Length header if data exists
|
|---|
| 3460 | headers.setContentLength(data.length, false);
|
|---|
| 3461 | if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
|
|---|
| 3462 | return reject(new AxiosError('Request body larger than maxBodyLength limit', AxiosError.ERR_BAD_REQUEST, config));
|
|---|
| 3463 | }
|
|---|
| 3464 | }
|
|---|
| 3465 | const contentLength = utils$1.toFiniteNumber(headers.getContentLength());
|
|---|
| 3466 | if (utils$1.isArray(maxRate)) {
|
|---|
| 3467 | maxUploadRate = maxRate[0];
|
|---|
| 3468 | maxDownloadRate = maxRate[1];
|
|---|
| 3469 | } else {
|
|---|
| 3470 | maxUploadRate = maxDownloadRate = maxRate;
|
|---|
| 3471 | }
|
|---|
| 3472 | if (data && (onUploadProgress || maxUploadRate)) {
|
|---|
| 3473 | if (!utils$1.isStream(data)) {
|
|---|
| 3474 | data = stream.Readable.from(data, {
|
|---|
| 3475 | objectMode: false
|
|---|
| 3476 | });
|
|---|
| 3477 | }
|
|---|
| 3478 | data = stream.pipeline([data, new AxiosTransformStream({
|
|---|
| 3479 | maxRate: utils$1.toFiniteNumber(maxUploadRate)
|
|---|
| 3480 | })], utils$1.noop);
|
|---|
| 3481 | onUploadProgress && data.on('progress', flushOnFinish(data, progressEventDecorator(contentLength, progressEventReducer(asyncDecorator(onUploadProgress), false, 3))));
|
|---|
| 3482 | }
|
|---|
| 3483 |
|
|---|
| 3484 | // HTTP basic authentication
|
|---|
| 3485 | let auth = undefined;
|
|---|
| 3486 | const configAuth = own('auth');
|
|---|
| 3487 | if (configAuth) {
|
|---|
| 3488 | const username = configAuth.username || '';
|
|---|
| 3489 | const password = configAuth.password || '';
|
|---|
| 3490 | auth = username + ':' + password;
|
|---|
| 3491 | }
|
|---|
| 3492 | if (!auth && parsed.username) {
|
|---|
| 3493 | const urlUsername = decodeURIComponentSafe(parsed.username);
|
|---|
| 3494 | const urlPassword = decodeURIComponentSafe(parsed.password);
|
|---|
| 3495 | auth = urlUsername + ':' + urlPassword;
|
|---|
| 3496 | }
|
|---|
| 3497 | auth && headers.delete('authorization');
|
|---|
| 3498 | let path$1;
|
|---|
| 3499 | try {
|
|---|
| 3500 | path$1 = buildURL(parsed.pathname + parsed.search, config.params, config.paramsSerializer).replace(/^\?/, '');
|
|---|
| 3501 | } catch (err) {
|
|---|
| 3502 | const customErr = new Error(err.message);
|
|---|
| 3503 | customErr.config = config;
|
|---|
| 3504 | customErr.url = config.url;
|
|---|
| 3505 | customErr.exists = true;
|
|---|
| 3506 | return reject(customErr);
|
|---|
| 3507 | }
|
|---|
| 3508 | headers.set('Accept-Encoding', 'gzip, compress, deflate' + (isBrotliSupported ? ', br' : ''), false);
|
|---|
| 3509 |
|
|---|
| 3510 | // Null-prototype to block prototype pollution gadgets on properties read
|
|---|
| 3511 | // directly by Node's http.request (e.g. insecureHTTPParser, lookup).
|
|---|
| 3512 | const options = Object.assign(Object.create(null), {
|
|---|
| 3513 | path: path$1,
|
|---|
| 3514 | method: method,
|
|---|
| 3515 | headers: toByteStringHeaderObject(headers),
|
|---|
| 3516 | agents: {
|
|---|
| 3517 | http: config.httpAgent,
|
|---|
| 3518 | https: config.httpsAgent
|
|---|
| 3519 | },
|
|---|
| 3520 | auth,
|
|---|
| 3521 | protocol,
|
|---|
| 3522 | family,
|
|---|
| 3523 | beforeRedirect: dispatchBeforeRedirect,
|
|---|
| 3524 | beforeRedirects: Object.create(null),
|
|---|
| 3525 | http2Options
|
|---|
| 3526 | });
|
|---|
| 3527 |
|
|---|
| 3528 | // cacheable-lookup integration hotfix
|
|---|
| 3529 | !utils$1.isUndefined(lookup) && (options.lookup = lookup);
|
|---|
| 3530 | if (config.socketPath) {
|
|---|
| 3531 | if (typeof config.socketPath !== 'string') {
|
|---|
| 3532 | return reject(new AxiosError('socketPath must be a string', AxiosError.ERR_BAD_OPTION_VALUE, config));
|
|---|
| 3533 | }
|
|---|
| 3534 | if (config.allowedSocketPaths != null) {
|
|---|
| 3535 | const allowed = Array.isArray(config.allowedSocketPaths) ? config.allowedSocketPaths : [config.allowedSocketPaths];
|
|---|
| 3536 | const resolvedSocket = path.resolve(config.socketPath);
|
|---|
| 3537 | const isAllowed = allowed.some(entry => typeof entry === 'string' && path.resolve(entry) === resolvedSocket);
|
|---|
| 3538 | if (!isAllowed) {
|
|---|
| 3539 | return reject(new AxiosError(`socketPath "${config.socketPath}" is not permitted by allowedSocketPaths`, AxiosError.ERR_BAD_OPTION_VALUE, config));
|
|---|
| 3540 | }
|
|---|
| 3541 | }
|
|---|
| 3542 | options.socketPath = config.socketPath;
|
|---|
| 3543 | } else {
|
|---|
| 3544 | options.hostname = parsed.hostname.startsWith('[') ? parsed.hostname.slice(1, -1) : parsed.hostname;
|
|---|
| 3545 | options.port = parsed.port;
|
|---|
| 3546 | setProxy(options, config.proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path, false, config.httpsAgent);
|
|---|
| 3547 | }
|
|---|
| 3548 | let transport;
|
|---|
| 3549 | let isNativeTransport = false;
|
|---|
| 3550 | const isHttpsRequest = isHttps.test(options.protocol);
|
|---|
| 3551 | // Don't clobber a CONNECT-tunneling agent installed by setProxy() for an
|
|---|
| 3552 | // HTTPS target.
|
|---|
| 3553 | if (options.agent == null) {
|
|---|
| 3554 | options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
|
|---|
| 3555 | }
|
|---|
| 3556 | if (isHttp2) {
|
|---|
| 3557 | transport = http2Transport;
|
|---|
| 3558 | } else {
|
|---|
| 3559 | const configTransport = own('transport');
|
|---|
| 3560 | if (configTransport) {
|
|---|
| 3561 | transport = configTransport;
|
|---|
| 3562 | } else if (config.maxRedirects === 0) {
|
|---|
| 3563 | transport = isHttpsRequest ? https : http;
|
|---|
| 3564 | isNativeTransport = true;
|
|---|
| 3565 | } else {
|
|---|
| 3566 | if (config.maxRedirects) {
|
|---|
| 3567 | options.maxRedirects = config.maxRedirects;
|
|---|
| 3568 | }
|
|---|
| 3569 | const configBeforeRedirect = own('beforeRedirect');
|
|---|
| 3570 | if (configBeforeRedirect) {
|
|---|
| 3571 | options.beforeRedirects.config = configBeforeRedirect;
|
|---|
| 3572 | }
|
|---|
| 3573 | transport = isHttpsRequest ? httpsFollow : httpFollow;
|
|---|
| 3574 | }
|
|---|
| 3575 | }
|
|---|
| 3576 | if (config.maxBodyLength > -1) {
|
|---|
| 3577 | options.maxBodyLength = config.maxBodyLength;
|
|---|
| 3578 | } else {
|
|---|
| 3579 | // follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
|
|---|
| 3580 | options.maxBodyLength = Infinity;
|
|---|
| 3581 | }
|
|---|
| 3582 |
|
|---|
| 3583 | // Always set an explicit own value so a polluted
|
|---|
| 3584 | // Object.prototype.insecureHTTPParser cannot enable the lenient parser
|
|---|
| 3585 | // through Node's internal options copy
|
|---|
| 3586 | options.insecureHTTPParser = Boolean(own('insecureHTTPParser'));
|
|---|
| 3587 |
|
|---|
| 3588 | // Create the request
|
|---|
| 3589 | req = transport.request(options, function handleResponse(res) {
|
|---|
| 3590 | clearConnectPhaseTimer();
|
|---|
| 3591 | if (req.destroyed) return;
|
|---|
| 3592 | const streams = [res];
|
|---|
| 3593 | const responseLength = utils$1.toFiniteNumber(res.headers['content-length']);
|
|---|
| 3594 | if (onDownloadProgress || maxDownloadRate) {
|
|---|
| 3595 | const transformStream = new AxiosTransformStream({
|
|---|
| 3596 | maxRate: utils$1.toFiniteNumber(maxDownloadRate)
|
|---|
| 3597 | });
|
|---|
| 3598 | onDownloadProgress && transformStream.on('progress', flushOnFinish(transformStream, progressEventDecorator(responseLength, progressEventReducer(asyncDecorator(onDownloadProgress), true, 3))));
|
|---|
| 3599 | streams.push(transformStream);
|
|---|
| 3600 | }
|
|---|
| 3601 |
|
|---|
| 3602 | // decompress the response body transparently if required
|
|---|
| 3603 | let responseStream = res;
|
|---|
| 3604 |
|
|---|
| 3605 | // return the last request in case of redirects
|
|---|
| 3606 | const lastRequest = res.req || req;
|
|---|
| 3607 |
|
|---|
| 3608 | // if decompress disabled we should not decompress
|
|---|
| 3609 | if (config.decompress !== false && res.headers['content-encoding']) {
|
|---|
| 3610 | // if no content, but headers still say that it is encoded,
|
|---|
| 3611 | // remove the header not confuse downstream operations
|
|---|
| 3612 | if (method === 'HEAD' || res.statusCode === 204) {
|
|---|
| 3613 | delete res.headers['content-encoding'];
|
|---|
| 3614 | }
|
|---|
| 3615 | switch ((res.headers['content-encoding'] || '').toLowerCase()) {
|
|---|
| 3616 | /*eslint default-case:0*/
|
|---|
| 3617 | case 'gzip':
|
|---|
| 3618 | case 'x-gzip':
|
|---|
| 3619 | case 'compress':
|
|---|
| 3620 | case 'x-compress':
|
|---|
| 3621 | // add the unzipper to the body stream processing pipeline
|
|---|
| 3622 | streams.push(zlib.createUnzip(zlibOptions));
|
|---|
| 3623 |
|
|---|
| 3624 | // remove the content-encoding in order to not confuse downstream operations
|
|---|
| 3625 | delete res.headers['content-encoding'];
|
|---|
| 3626 | break;
|
|---|
| 3627 | case 'deflate':
|
|---|
| 3628 | streams.push(new ZlibHeaderTransformStream());
|
|---|
| 3629 |
|
|---|
| 3630 | // add the unzipper to the body stream processing pipeline
|
|---|
| 3631 | streams.push(zlib.createUnzip(zlibOptions));
|
|---|
| 3632 |
|
|---|
| 3633 | // remove the content-encoding in order to not confuse downstream operations
|
|---|
| 3634 | delete res.headers['content-encoding'];
|
|---|
| 3635 | break;
|
|---|
| 3636 | case 'br':
|
|---|
| 3637 | if (isBrotliSupported) {
|
|---|
| 3638 | streams.push(zlib.createBrotliDecompress(brotliOptions));
|
|---|
| 3639 | delete res.headers['content-encoding'];
|
|---|
| 3640 | }
|
|---|
| 3641 | }
|
|---|
| 3642 | }
|
|---|
| 3643 | responseStream = streams.length > 1 ? stream.pipeline(streams, utils$1.noop) : streams[0];
|
|---|
| 3644 | const response = {
|
|---|
| 3645 | status: res.statusCode,
|
|---|
| 3646 | statusText: res.statusMessage,
|
|---|
| 3647 | headers: new AxiosHeaders(res.headers),
|
|---|
| 3648 | config,
|
|---|
| 3649 | request: lastRequest
|
|---|
| 3650 | };
|
|---|
| 3651 | if (responseType === 'stream') {
|
|---|
| 3652 | // Enforce maxContentLength on streamed responses; previously this
|
|---|
| 3653 | // was applied only to buffered responses.
|
|---|
| 3654 | if (config.maxContentLength > -1) {
|
|---|
| 3655 | const limit = config.maxContentLength;
|
|---|
| 3656 | const source = responseStream;
|
|---|
| 3657 | async function* enforceMaxContentLength() {
|
|---|
| 3658 | let totalResponseBytes = 0;
|
|---|
| 3659 | for await (const chunk of source) {
|
|---|
| 3660 | totalResponseBytes += chunk.length;
|
|---|
| 3661 | if (totalResponseBytes > limit) {
|
|---|
| 3662 | throw new AxiosError('maxContentLength size of ' + limit + ' exceeded', AxiosError.ERR_BAD_RESPONSE, config, lastRequest);
|
|---|
| 3663 | }
|
|---|
| 3664 | yield chunk;
|
|---|
| 3665 | }
|
|---|
| 3666 | }
|
|---|
| 3667 | responseStream = stream.Readable.from(enforceMaxContentLength(), {
|
|---|
| 3668 | objectMode: false
|
|---|
| 3669 | });
|
|---|
| 3670 | }
|
|---|
| 3671 | response.data = responseStream;
|
|---|
| 3672 | settle(resolve, reject, response);
|
|---|
| 3673 | } else {
|
|---|
| 3674 | const responseBuffer = [];
|
|---|
| 3675 | let totalResponseBytes = 0;
|
|---|
| 3676 | responseStream.on('data', function handleStreamData(chunk) {
|
|---|
| 3677 | responseBuffer.push(chunk);
|
|---|
| 3678 | totalResponseBytes += chunk.length;
|
|---|
| 3679 |
|
|---|
| 3680 | // make sure the content length is not over the maxContentLength if specified
|
|---|
| 3681 | if (config.maxContentLength > -1 && totalResponseBytes > config.maxContentLength) {
|
|---|
| 3682 | // stream.destroy() emit aborted event before calling reject() on Node.js v16
|
|---|
| 3683 | rejected = true;
|
|---|
| 3684 | responseStream.destroy();
|
|---|
| 3685 | abort(new AxiosError('maxContentLength size of ' + config.maxContentLength + ' exceeded', AxiosError.ERR_BAD_RESPONSE, config, lastRequest));
|
|---|
| 3686 | }
|
|---|
| 3687 | });
|
|---|
| 3688 | responseStream.on('aborted', function handlerStreamAborted() {
|
|---|
| 3689 | if (rejected) {
|
|---|
| 3690 | return;
|
|---|
| 3691 | }
|
|---|
| 3692 | const err = new AxiosError('stream has been aborted', AxiosError.ERR_BAD_RESPONSE, config, lastRequest, response);
|
|---|
| 3693 | responseStream.destroy(err);
|
|---|
| 3694 | reject(err);
|
|---|
| 3695 | });
|
|---|
| 3696 | responseStream.on('error', function handleStreamError(err) {
|
|---|
| 3697 | if (rejected) return;
|
|---|
| 3698 | reject(AxiosError.from(err, null, config, lastRequest, response));
|
|---|
| 3699 | });
|
|---|
| 3700 | responseStream.on('end', function handleStreamEnd() {
|
|---|
| 3701 | try {
|
|---|
| 3702 | let responseData = responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer);
|
|---|
| 3703 | if (responseType !== 'arraybuffer') {
|
|---|
| 3704 | responseData = responseData.toString(responseEncoding);
|
|---|
| 3705 | if (!responseEncoding || responseEncoding === 'utf8') {
|
|---|
| 3706 | responseData = utils$1.stripBOM(responseData);
|
|---|
| 3707 | }
|
|---|
| 3708 | }
|
|---|
| 3709 | response.data = responseData;
|
|---|
| 3710 | } catch (err) {
|
|---|
| 3711 | return reject(AxiosError.from(err, null, config, response.request, response));
|
|---|
| 3712 | }
|
|---|
| 3713 | settle(resolve, reject, response);
|
|---|
| 3714 | });
|
|---|
| 3715 | }
|
|---|
| 3716 | abortEmitter.once('abort', err => {
|
|---|
| 3717 | if (!responseStream.destroyed) {
|
|---|
| 3718 | responseStream.emit('error', err);
|
|---|
| 3719 | responseStream.destroy();
|
|---|
| 3720 | }
|
|---|
| 3721 | });
|
|---|
| 3722 | });
|
|---|
| 3723 | abortEmitter.once('abort', err => {
|
|---|
| 3724 | if (req.close) {
|
|---|
| 3725 | req.close();
|
|---|
| 3726 | } else {
|
|---|
| 3727 | req.destroy(err);
|
|---|
| 3728 | }
|
|---|
| 3729 | });
|
|---|
| 3730 |
|
|---|
| 3731 | // Handle errors
|
|---|
| 3732 | req.on('error', function handleRequestError(err) {
|
|---|
| 3733 | reject(AxiosError.from(err, null, config, req));
|
|---|
| 3734 | });
|
|---|
| 3735 |
|
|---|
| 3736 | // set tcp keep alive to prevent drop connection by peer
|
|---|
| 3737 | // Track every socket bound to this outer RedirectableRequest so a single
|
|---|
| 3738 | // 'close' listener can release ownership on all of them. follow-redirects
|
|---|
| 3739 | // re-emits the 'socket' event for each hop's native request onto the same
|
|---|
| 3740 | // outer request, so attaching per-request listeners inside this handler
|
|---|
| 3741 | // would accumulate across hops and trigger MaxListenersExceededWarning at
|
|---|
| 3742 | // >= 11 redirects. Clearing only the last-bound socket would leave stale
|
|---|
| 3743 | // kAxiosCurrentReq refs on earlier hop sockets returned to the keep-alive
|
|---|
| 3744 | // pool, causing an idle-pool 'error' to be attributed to a closed req.
|
|---|
| 3745 | const boundSockets = new Set();
|
|---|
| 3746 | req.on('socket', function handleRequestSocket(socket) {
|
|---|
| 3747 | // default interval of sending ack packet is 1 minute
|
|---|
| 3748 | socket.setKeepAlive(true, 1000 * 60);
|
|---|
| 3749 |
|
|---|
| 3750 | // Install a single 'error' listener per socket (not per request) to avoid
|
|---|
| 3751 | // accumulating listeners on pooled keep-alive sockets that get reassigned
|
|---|
| 3752 | // to new requests before the previous request's 'close' fires (issue #10780).
|
|---|
| 3753 | // The listener is bound to the socket's currently-active request via a
|
|---|
| 3754 | // symbol, which is swapped as the socket is reassigned.
|
|---|
| 3755 | if (!socket[kAxiosSocketListener]) {
|
|---|
| 3756 | socket.on('error', function handleSocketError(err) {
|
|---|
| 3757 | const current = socket[kAxiosCurrentReq];
|
|---|
| 3758 | if (current && !current.destroyed) {
|
|---|
| 3759 | current.destroy(err);
|
|---|
| 3760 | }
|
|---|
| 3761 | });
|
|---|
| 3762 | socket[kAxiosSocketListener] = true;
|
|---|
| 3763 | }
|
|---|
| 3764 | socket[kAxiosCurrentReq] = req;
|
|---|
| 3765 | boundSockets.add(socket);
|
|---|
| 3766 | });
|
|---|
| 3767 | req.once('close', function clearCurrentReq() {
|
|---|
| 3768 | clearConnectPhaseTimer();
|
|---|
| 3769 | for (const socket of boundSockets) {
|
|---|
| 3770 | if (socket[kAxiosCurrentReq] === req) {
|
|---|
| 3771 | socket[kAxiosCurrentReq] = null;
|
|---|
| 3772 | }
|
|---|
| 3773 | }
|
|---|
| 3774 | boundSockets.clear();
|
|---|
| 3775 | });
|
|---|
| 3776 |
|
|---|
| 3777 | // Handle request timeout
|
|---|
| 3778 | if (config.timeout) {
|
|---|
| 3779 | // This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.
|
|---|
| 3780 | const timeout = parseInt(config.timeout, 10);
|
|---|
| 3781 | if (Number.isNaN(timeout)) {
|
|---|
| 3782 | abort(new AxiosError('error trying to parse `config.timeout` to int', AxiosError.ERR_BAD_OPTION_VALUE, config, req));
|
|---|
| 3783 | return;
|
|---|
| 3784 | }
|
|---|
| 3785 | const handleTimeout = function handleTimeout() {
|
|---|
| 3786 | if (isDone) return;
|
|---|
| 3787 | abort(createTimeoutError());
|
|---|
| 3788 | };
|
|---|
| 3789 | if (isNativeTransport && timeout > 0) {
|
|---|
| 3790 | // Native ClientRequest#setTimeout starts from the socket lifecycle and
|
|---|
| 3791 | // may not fire while TCP connect is still pending. Mirror the
|
|---|
| 3792 | // follow-redirects wall-clock timer for the maxRedirects === 0 path.
|
|---|
| 3793 | connectPhaseTimer = setTimeout(handleTimeout, timeout);
|
|---|
| 3794 | }
|
|---|
| 3795 |
|
|---|
| 3796 | // Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
|
|---|
| 3797 | // And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
|
|---|
| 3798 | // At this time, if we have a large number of request, nodejs will hang up some socket on background. and the number will up and up.
|
|---|
| 3799 | // And then these socket which be hang up will devouring CPU little by little.
|
|---|
| 3800 | // ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
|
|---|
| 3801 | req.setTimeout(timeout, handleTimeout);
|
|---|
| 3802 | } else {
|
|---|
| 3803 | // explicitly reset the socket timeout value for a possible `keep-alive` request
|
|---|
| 3804 | req.setTimeout(0);
|
|---|
| 3805 | }
|
|---|
| 3806 |
|
|---|
| 3807 | // Send the request
|
|---|
| 3808 | if (utils$1.isStream(data)) {
|
|---|
| 3809 | let ended = false;
|
|---|
| 3810 | let errored = false;
|
|---|
| 3811 | data.on('end', () => {
|
|---|
| 3812 | ended = true;
|
|---|
| 3813 | });
|
|---|
| 3814 | data.once('error', err => {
|
|---|
| 3815 | errored = true;
|
|---|
| 3816 | req.destroy(err);
|
|---|
| 3817 | });
|
|---|
| 3818 | data.on('close', () => {
|
|---|
| 3819 | if (!ended && !errored) {
|
|---|
| 3820 | abort(new CanceledError('Request stream has been aborted', config, req));
|
|---|
| 3821 | }
|
|---|
| 3822 | });
|
|---|
| 3823 |
|
|---|
| 3824 | // Enforce maxBodyLength for streamed uploads on the native http/https
|
|---|
| 3825 | // transport (maxRedirects === 0); follow-redirects enforces it on the
|
|---|
| 3826 | // other path.
|
|---|
| 3827 | let uploadStream = data;
|
|---|
| 3828 | if (config.maxBodyLength > -1 && config.maxRedirects === 0) {
|
|---|
| 3829 | const limit = config.maxBodyLength;
|
|---|
| 3830 | let bytesSent = 0;
|
|---|
| 3831 | uploadStream = stream.pipeline([data, new stream.Transform({
|
|---|
| 3832 | transform(chunk, _enc, cb) {
|
|---|
| 3833 | bytesSent += chunk.length;
|
|---|
| 3834 | if (bytesSent > limit) {
|
|---|
| 3835 | return cb(new AxiosError('Request body larger than maxBodyLength limit', AxiosError.ERR_BAD_REQUEST, config, req));
|
|---|
| 3836 | }
|
|---|
| 3837 | cb(null, chunk);
|
|---|
| 3838 | }
|
|---|
| 3839 | })], utils$1.noop);
|
|---|
| 3840 | uploadStream.on('error', err => {
|
|---|
| 3841 | if (!req.destroyed) req.destroy(err);
|
|---|
| 3842 | });
|
|---|
| 3843 | }
|
|---|
| 3844 | uploadStream.pipe(req);
|
|---|
| 3845 | } else {
|
|---|
| 3846 | data && req.write(data);
|
|---|
| 3847 | req.end();
|
|---|
| 3848 | }
|
|---|
| 3849 | });
|
|---|
| 3850 | };
|
|---|
| 3851 |
|
|---|
| 3852 | var isURLSameOrigin = platform.hasStandardBrowserEnv ? ((origin, isMSIE) => url => {
|
|---|
| 3853 | url = new URL(url, platform.origin);
|
|---|
| 3854 | return origin.protocol === url.protocol && origin.host === url.host && (isMSIE || origin.port === url.port);
|
|---|
| 3855 | })(new URL(platform.origin), platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)) : () => true;
|
|---|
| 3856 |
|
|---|
| 3857 | var cookies = platform.hasStandardBrowserEnv ?
|
|---|
| 3858 | // Standard browser envs support document.cookie
|
|---|
| 3859 | {
|
|---|
| 3860 | write(name, value, expires, path, domain, secure, sameSite) {
|
|---|
| 3861 | if (typeof document === 'undefined') return;
|
|---|
| 3862 | const cookie = [`${name}=${encodeURIComponent(value)}`];
|
|---|
| 3863 | if (utils$1.isNumber(expires)) {
|
|---|
| 3864 | cookie.push(`expires=${new Date(expires).toUTCString()}`);
|
|---|
| 3865 | }
|
|---|
| 3866 | if (utils$1.isString(path)) {
|
|---|
| 3867 | cookie.push(`path=${path}`);
|
|---|
| 3868 | }
|
|---|
| 3869 | if (utils$1.isString(domain)) {
|
|---|
| 3870 | cookie.push(`domain=${domain}`);
|
|---|
| 3871 | }
|
|---|
| 3872 | if (secure === true) {
|
|---|
| 3873 | cookie.push('secure');
|
|---|
| 3874 | }
|
|---|
| 3875 | if (utils$1.isString(sameSite)) {
|
|---|
| 3876 | cookie.push(`SameSite=${sameSite}`);
|
|---|
| 3877 | }
|
|---|
| 3878 | document.cookie = cookie.join('; ');
|
|---|
| 3879 | },
|
|---|
| 3880 | read(name) {
|
|---|
| 3881 | if (typeof document === 'undefined') return null;
|
|---|
| 3882 | // Match name=value by splitting on the semicolon separator instead of building a
|
|---|
| 3883 | // RegExp from `name` — interpolating an unescaped string into a RegExp would let
|
|---|
| 3884 | // metacharacters (e.g. `.+?` in an attacker-influenced cookie name) cause ReDoS or
|
|---|
| 3885 | // match the wrong cookie. Browsers may serialize cookie pairs as either ";" or
|
|---|
| 3886 | // "; ", so ignore optional whitespace before each cookie name.
|
|---|
| 3887 | const cookies = document.cookie.split(';');
|
|---|
| 3888 | for (let i = 0; i < cookies.length; i++) {
|
|---|
| 3889 | const cookie = cookies[i].replace(/^\s+/, '');
|
|---|
| 3890 | const eq = cookie.indexOf('=');
|
|---|
| 3891 | if (eq !== -1 && cookie.slice(0, eq) === name) {
|
|---|
| 3892 | return decodeURIComponent(cookie.slice(eq + 1));
|
|---|
| 3893 | }
|
|---|
| 3894 | }
|
|---|
| 3895 | return null;
|
|---|
| 3896 | },
|
|---|
| 3897 | remove(name) {
|
|---|
| 3898 | this.write(name, '', Date.now() - 86400000, '/');
|
|---|
| 3899 | }
|
|---|
| 3900 | } :
|
|---|
| 3901 | // Non-standard browser env (web workers, react-native) lack needed support.
|
|---|
| 3902 | {
|
|---|
| 3903 | write() {},
|
|---|
| 3904 | read() {
|
|---|
| 3905 | return null;
|
|---|
| 3906 | },
|
|---|
| 3907 | remove() {}
|
|---|
| 3908 | };
|
|---|
| 3909 |
|
|---|
| 3910 | const headersToObject = thing => thing instanceof AxiosHeaders ? {
|
|---|
| 3911 | ...thing
|
|---|
| 3912 | } : thing;
|
|---|
| 3913 |
|
|---|
| 3914 | /**
|
|---|
| 3915 | * Config-specific merge-function which creates a new config-object
|
|---|
| 3916 | * by merging two configuration objects together.
|
|---|
| 3917 | *
|
|---|
| 3918 | * @param {Object} config1
|
|---|
| 3919 | * @param {Object} config2
|
|---|
| 3920 | *
|
|---|
| 3921 | * @returns {Object} New object resulting from merging config2 to config1
|
|---|
| 3922 | */
|
|---|
| 3923 | function mergeConfig(config1, config2) {
|
|---|
| 3924 | // eslint-disable-next-line no-param-reassign
|
|---|
| 3925 | config2 = config2 || {};
|
|---|
| 3926 |
|
|---|
| 3927 | // Use a null-prototype object so that downstream reads such as `config.auth`
|
|---|
| 3928 | // or `config.baseURL` cannot inherit polluted values from Object.prototype.
|
|---|
| 3929 | // `hasOwnProperty` is restored as a non-enumerable own slot to preserve
|
|---|
| 3930 | // ergonomics for user code that relies on it.
|
|---|
| 3931 | const config = Object.create(null);
|
|---|
| 3932 | Object.defineProperty(config, 'hasOwnProperty', {
|
|---|
| 3933 | // Null-proto descriptor so a polluted Object.prototype.get cannot turn
|
|---|
| 3934 | // this data descriptor into an accessor descriptor on the way in.
|
|---|
| 3935 | __proto__: null,
|
|---|
| 3936 | value: Object.prototype.hasOwnProperty,
|
|---|
| 3937 | enumerable: false,
|
|---|
| 3938 | writable: true,
|
|---|
| 3939 | configurable: true
|
|---|
| 3940 | });
|
|---|
| 3941 | function getMergedValue(target, source, prop, caseless) {
|
|---|
| 3942 | if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
|
|---|
| 3943 | return utils$1.merge.call({
|
|---|
| 3944 | caseless
|
|---|
| 3945 | }, target, source);
|
|---|
| 3946 | } else if (utils$1.isPlainObject(source)) {
|
|---|
| 3947 | return utils$1.merge({}, source);
|
|---|
| 3948 | } else if (utils$1.isArray(source)) {
|
|---|
| 3949 | return source.slice();
|
|---|
| 3950 | }
|
|---|
| 3951 | return source;
|
|---|
| 3952 | }
|
|---|
| 3953 | function mergeDeepProperties(a, b, prop, caseless) {
|
|---|
| 3954 | if (!utils$1.isUndefined(b)) {
|
|---|
| 3955 | return getMergedValue(a, b, prop, caseless);
|
|---|
| 3956 | } else if (!utils$1.isUndefined(a)) {
|
|---|
| 3957 | return getMergedValue(undefined, a, prop, caseless);
|
|---|
| 3958 | }
|
|---|
| 3959 | }
|
|---|
| 3960 |
|
|---|
| 3961 | // eslint-disable-next-line consistent-return
|
|---|
| 3962 | function valueFromConfig2(a, b) {
|
|---|
| 3963 | if (!utils$1.isUndefined(b)) {
|
|---|
| 3964 | return getMergedValue(undefined, b);
|
|---|
| 3965 | }
|
|---|
| 3966 | }
|
|---|
| 3967 |
|
|---|
| 3968 | // eslint-disable-next-line consistent-return
|
|---|
| 3969 | function defaultToConfig2(a, b) {
|
|---|
| 3970 | if (!utils$1.isUndefined(b)) {
|
|---|
| 3971 | return getMergedValue(undefined, b);
|
|---|
| 3972 | } else if (!utils$1.isUndefined(a)) {
|
|---|
| 3973 | return getMergedValue(undefined, a);
|
|---|
| 3974 | }
|
|---|
| 3975 | }
|
|---|
| 3976 |
|
|---|
| 3977 | // eslint-disable-next-line consistent-return
|
|---|
| 3978 | function mergeDirectKeys(a, b, prop) {
|
|---|
| 3979 | if (utils$1.hasOwnProp(config2, prop)) {
|
|---|
| 3980 | return getMergedValue(a, b);
|
|---|
| 3981 | } else if (utils$1.hasOwnProp(config1, prop)) {
|
|---|
| 3982 | return getMergedValue(undefined, a);
|
|---|
| 3983 | }
|
|---|
| 3984 | }
|
|---|
| 3985 | const mergeMap = {
|
|---|
| 3986 | url: valueFromConfig2,
|
|---|
| 3987 | method: valueFromConfig2,
|
|---|
| 3988 | data: valueFromConfig2,
|
|---|
| 3989 | baseURL: defaultToConfig2,
|
|---|
| 3990 | transformRequest: defaultToConfig2,
|
|---|
| 3991 | transformResponse: defaultToConfig2,
|
|---|
| 3992 | paramsSerializer: defaultToConfig2,
|
|---|
| 3993 | timeout: defaultToConfig2,
|
|---|
| 3994 | timeoutMessage: defaultToConfig2,
|
|---|
| 3995 | withCredentials: defaultToConfig2,
|
|---|
| 3996 | withXSRFToken: defaultToConfig2,
|
|---|
| 3997 | adapter: defaultToConfig2,
|
|---|
| 3998 | responseType: defaultToConfig2,
|
|---|
| 3999 | xsrfCookieName: defaultToConfig2,
|
|---|
| 4000 | xsrfHeaderName: defaultToConfig2,
|
|---|
| 4001 | onUploadProgress: defaultToConfig2,
|
|---|
| 4002 | onDownloadProgress: defaultToConfig2,
|
|---|
| 4003 | decompress: defaultToConfig2,
|
|---|
| 4004 | maxContentLength: defaultToConfig2,
|
|---|
| 4005 | maxBodyLength: defaultToConfig2,
|
|---|
| 4006 | beforeRedirect: defaultToConfig2,
|
|---|
| 4007 | transport: defaultToConfig2,
|
|---|
| 4008 | httpAgent: defaultToConfig2,
|
|---|
| 4009 | httpsAgent: defaultToConfig2,
|
|---|
| 4010 | cancelToken: defaultToConfig2,
|
|---|
| 4011 | socketPath: defaultToConfig2,
|
|---|
| 4012 | allowedSocketPaths: defaultToConfig2,
|
|---|
| 4013 | responseEncoding: defaultToConfig2,
|
|---|
| 4014 | validateStatus: mergeDirectKeys,
|
|---|
| 4015 | headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
|
|---|
| 4016 | };
|
|---|
| 4017 | utils$1.forEach(Object.keys({
|
|---|
| 4018 | ...config1,
|
|---|
| 4019 | ...config2
|
|---|
| 4020 | }), function computeConfigValue(prop) {
|
|---|
| 4021 | if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') return;
|
|---|
| 4022 | const merge = utils$1.hasOwnProp(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties;
|
|---|
| 4023 | const a = utils$1.hasOwnProp(config1, prop) ? config1[prop] : undefined;
|
|---|
| 4024 | const b = utils$1.hasOwnProp(config2, prop) ? config2[prop] : undefined;
|
|---|
| 4025 | const configValue = merge(a, b, prop);
|
|---|
| 4026 | utils$1.isUndefined(configValue) && merge !== mergeDirectKeys || (config[prop] = configValue);
|
|---|
| 4027 | });
|
|---|
| 4028 | return config;
|
|---|
| 4029 | }
|
|---|
| 4030 |
|
|---|
| 4031 | const FORM_DATA_CONTENT_HEADERS = ['content-type', 'content-length'];
|
|---|
| 4032 | function setFormDataHeaders(headers, formHeaders, policy) {
|
|---|
| 4033 | if (policy !== 'content-only') {
|
|---|
| 4034 | headers.set(formHeaders);
|
|---|
| 4035 | return;
|
|---|
| 4036 | }
|
|---|
| 4037 | Object.entries(formHeaders).forEach(([key, val]) => {
|
|---|
| 4038 | if (FORM_DATA_CONTENT_HEADERS.includes(key.toLowerCase())) {
|
|---|
| 4039 | headers.set(key, val);
|
|---|
| 4040 | }
|
|---|
| 4041 | });
|
|---|
| 4042 | }
|
|---|
| 4043 |
|
|---|
| 4044 | /**
|
|---|
| 4045 | * Encode a UTF-8 string to a Latin-1 byte string for use with btoa().
|
|---|
| 4046 | * This is a modern replacement for the deprecated unescape(encodeURIComponent(str)) pattern.
|
|---|
| 4047 | *
|
|---|
| 4048 | * @param {string} str The string to encode
|
|---|
| 4049 | *
|
|---|
| 4050 | * @returns {string} UTF-8 bytes as a Latin-1 string
|
|---|
| 4051 | */
|
|---|
| 4052 | const encodeUTF8 = str => encodeURIComponent(str).replace(/%([0-9A-F]{2})/gi, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
|
|---|
| 4053 | var resolveConfig = config => {
|
|---|
| 4054 | const newConfig = mergeConfig({}, config);
|
|---|
| 4055 |
|
|---|
| 4056 | // Read only own properties to prevent prototype pollution gadgets
|
|---|
| 4057 | // (e.g. Object.prototype.baseURL = 'https://evil.com').
|
|---|
| 4058 | const own = key => utils$1.hasOwnProp(newConfig, key) ? newConfig[key] : undefined;
|
|---|
| 4059 | const data = own('data');
|
|---|
| 4060 | let withXSRFToken = own('withXSRFToken');
|
|---|
| 4061 | const xsrfHeaderName = own('xsrfHeaderName');
|
|---|
| 4062 | const xsrfCookieName = own('xsrfCookieName');
|
|---|
| 4063 | let headers = own('headers');
|
|---|
| 4064 | const auth = own('auth');
|
|---|
| 4065 | const baseURL = own('baseURL');
|
|---|
| 4066 | const allowAbsoluteUrls = own('allowAbsoluteUrls');
|
|---|
| 4067 | const url = own('url');
|
|---|
| 4068 | newConfig.headers = headers = AxiosHeaders.from(headers);
|
|---|
| 4069 | newConfig.url = buildURL(buildFullPath(baseURL, url, allowAbsoluteUrls), config.params, config.paramsSerializer);
|
|---|
| 4070 |
|
|---|
| 4071 | // HTTP basic authentication
|
|---|
| 4072 | if (auth) {
|
|---|
| 4073 | headers.set('Authorization', 'Basic ' + btoa((auth.username || '') + ':' + (auth.password ? encodeUTF8(auth.password) : '')));
|
|---|
| 4074 | }
|
|---|
| 4075 | if (utils$1.isFormData(data)) {
|
|---|
| 4076 | if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
|---|
| 4077 | headers.setContentType(undefined); // browser handles it
|
|---|
| 4078 | } else if (utils$1.isFunction(data.getHeaders)) {
|
|---|
| 4079 | // Node.js FormData (like form-data package)
|
|---|
| 4080 | setFormDataHeaders(headers, data.getHeaders(), own('formDataHeaderPolicy'));
|
|---|
| 4081 | }
|
|---|
| 4082 | }
|
|---|
| 4083 |
|
|---|
| 4084 | // Add xsrf header
|
|---|
| 4085 | // This is only done if running in a standard browser environment.
|
|---|
| 4086 | // Specifically not if we're in a web worker, or react-native.
|
|---|
| 4087 |
|
|---|
| 4088 | if (platform.hasStandardBrowserEnv) {
|
|---|
| 4089 | if (utils$1.isFunction(withXSRFToken)) {
|
|---|
| 4090 | withXSRFToken = withXSRFToken(newConfig);
|
|---|
| 4091 | }
|
|---|
| 4092 |
|
|---|
| 4093 | // Strict boolean check — prevents proto-pollution gadgets (e.g. Object.prototype.withXSRFToken = 1)
|
|---|
| 4094 | // and misconfigurations (e.g. "false") from short-circuiting the same-origin check and leaking
|
|---|
| 4095 | // the XSRF token cross-origin.
|
|---|
| 4096 | const shouldSendXSRF = withXSRFToken === true || withXSRFToken == null && isURLSameOrigin(newConfig.url);
|
|---|
| 4097 | if (shouldSendXSRF) {
|
|---|
| 4098 | const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
|
|---|
| 4099 | if (xsrfValue) {
|
|---|
| 4100 | headers.set(xsrfHeaderName, xsrfValue);
|
|---|
| 4101 | }
|
|---|
| 4102 | }
|
|---|
| 4103 | }
|
|---|
| 4104 | return newConfig;
|
|---|
| 4105 | };
|
|---|
| 4106 |
|
|---|
| 4107 | const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
|
|---|
| 4108 | var xhrAdapter = isXHRAdapterSupported && function (config) {
|
|---|
| 4109 | return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|---|
| 4110 | const _config = resolveConfig(config);
|
|---|
| 4111 | let requestData = _config.data;
|
|---|
| 4112 | const requestHeaders = AxiosHeaders.from(_config.headers).normalize();
|
|---|
| 4113 | let {
|
|---|
| 4114 | responseType,
|
|---|
| 4115 | onUploadProgress,
|
|---|
| 4116 | onDownloadProgress
|
|---|
| 4117 | } = _config;
|
|---|
| 4118 | let onCanceled;
|
|---|
| 4119 | let uploadThrottled, downloadThrottled;
|
|---|
| 4120 | let flushUpload, flushDownload;
|
|---|
| 4121 | function done() {
|
|---|
| 4122 | flushUpload && flushUpload(); // flush events
|
|---|
| 4123 | flushDownload && flushDownload(); // flush events
|
|---|
| 4124 |
|
|---|
| 4125 | _config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
|---|
| 4126 | _config.signal && _config.signal.removeEventListener('abort', onCanceled);
|
|---|
| 4127 | }
|
|---|
| 4128 | let request = new XMLHttpRequest();
|
|---|
| 4129 | request.open(_config.method.toUpperCase(), _config.url, true);
|
|---|
| 4130 |
|
|---|
| 4131 | // Set the request timeout in MS
|
|---|
| 4132 | request.timeout = _config.timeout;
|
|---|
| 4133 | function onloadend() {
|
|---|
| 4134 | if (!request) {
|
|---|
| 4135 | return;
|
|---|
| 4136 | }
|
|---|
| 4137 | // Prepare the response
|
|---|
| 4138 | const responseHeaders = AxiosHeaders.from('getAllResponseHeaders' in request && request.getAllResponseHeaders());
|
|---|
| 4139 | const responseData = !responseType || responseType === 'text' || responseType === 'json' ? request.responseText : request.response;
|
|---|
| 4140 | const response = {
|
|---|
| 4141 | data: responseData,
|
|---|
| 4142 | status: request.status,
|
|---|
| 4143 | statusText: request.statusText,
|
|---|
| 4144 | headers: responseHeaders,
|
|---|
| 4145 | config,
|
|---|
| 4146 | request
|
|---|
| 4147 | };
|
|---|
| 4148 | settle(function _resolve(value) {
|
|---|
| 4149 | resolve(value);
|
|---|
| 4150 | done();
|
|---|
| 4151 | }, function _reject(err) {
|
|---|
| 4152 | reject(err);
|
|---|
| 4153 | done();
|
|---|
| 4154 | }, response);
|
|---|
| 4155 |
|
|---|
| 4156 | // Clean up request
|
|---|
| 4157 | request = null;
|
|---|
| 4158 | }
|
|---|
| 4159 | if ('onloadend' in request) {
|
|---|
| 4160 | // Use onloadend if available
|
|---|
| 4161 | request.onloadend = onloadend;
|
|---|
| 4162 | } else {
|
|---|
| 4163 | // Listen for ready state to emulate onloadend
|
|---|
| 4164 | request.onreadystatechange = function handleLoad() {
|
|---|
| 4165 | if (!request || request.readyState !== 4) {
|
|---|
| 4166 | return;
|
|---|
| 4167 | }
|
|---|
| 4168 |
|
|---|
| 4169 | // The request errored out and we didn't get a response, this will be
|
|---|
| 4170 | // handled by onerror instead
|
|---|
| 4171 | // With one exception: request that using file: protocol, most browsers
|
|---|
| 4172 | // will return status as 0 even though it's a successful request
|
|---|
| 4173 | if (request.status === 0 && !(request.responseURL && request.responseURL.startsWith('file:'))) {
|
|---|
| 4174 | return;
|
|---|
| 4175 | }
|
|---|
| 4176 | // readystate handler is calling before onerror or ontimeout handlers,
|
|---|
| 4177 | // so we should call onloadend on the next 'tick'
|
|---|
| 4178 | setTimeout(onloadend);
|
|---|
| 4179 | };
|
|---|
| 4180 | }
|
|---|
| 4181 |
|
|---|
| 4182 | // Handle browser request cancellation (as opposed to a manual cancellation)
|
|---|
| 4183 | request.onabort = function handleAbort() {
|
|---|
| 4184 | if (!request) {
|
|---|
| 4185 | return;
|
|---|
| 4186 | }
|
|---|
| 4187 | reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
|
|---|
| 4188 | done();
|
|---|
| 4189 |
|
|---|
| 4190 | // Clean up request
|
|---|
| 4191 | request = null;
|
|---|
| 4192 | };
|
|---|
| 4193 |
|
|---|
| 4194 | // Handle low level network errors
|
|---|
| 4195 | request.onerror = function handleError(event) {
|
|---|
| 4196 | // Browsers deliver a ProgressEvent in XHR onerror
|
|---|
| 4197 | // (message may be empty; when present, surface it)
|
|---|
| 4198 | // See https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/error_event
|
|---|
| 4199 | const msg = event && event.message ? event.message : 'Network Error';
|
|---|
| 4200 | const err = new AxiosError(msg, AxiosError.ERR_NETWORK, config, request);
|
|---|
| 4201 | // attach the underlying event for consumers who want details
|
|---|
| 4202 | err.event = event || null;
|
|---|
| 4203 | reject(err);
|
|---|
| 4204 | done();
|
|---|
| 4205 | request = null;
|
|---|
| 4206 | };
|
|---|
| 4207 |
|
|---|
| 4208 | // Handle timeout
|
|---|
| 4209 | request.ontimeout = function handleTimeout() {
|
|---|
| 4210 | let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
|
|---|
| 4211 | const transitional = _config.transitional || transitionalDefaults;
|
|---|
| 4212 | if (_config.timeoutErrorMessage) {
|
|---|
| 4213 | timeoutErrorMessage = _config.timeoutErrorMessage;
|
|---|
| 4214 | }
|
|---|
| 4215 | reject(new AxiosError(timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, config, request));
|
|---|
| 4216 | done();
|
|---|
| 4217 |
|
|---|
| 4218 | // Clean up request
|
|---|
| 4219 | request = null;
|
|---|
| 4220 | };
|
|---|
| 4221 |
|
|---|
| 4222 | // Remove Content-Type if data is undefined
|
|---|
| 4223 | requestData === undefined && requestHeaders.setContentType(null);
|
|---|
| 4224 |
|
|---|
| 4225 | // Add headers to the request
|
|---|
| 4226 | if ('setRequestHeader' in request) {
|
|---|
| 4227 | utils$1.forEach(toByteStringHeaderObject(requestHeaders), function setRequestHeader(val, key) {
|
|---|
| 4228 | request.setRequestHeader(key, val);
|
|---|
| 4229 | });
|
|---|
| 4230 | }
|
|---|
| 4231 |
|
|---|
| 4232 | // Add withCredentials to request if needed
|
|---|
| 4233 | if (!utils$1.isUndefined(_config.withCredentials)) {
|
|---|
| 4234 | request.withCredentials = !!_config.withCredentials;
|
|---|
| 4235 | }
|
|---|
| 4236 |
|
|---|
| 4237 | // Add responseType to request if needed
|
|---|
| 4238 | if (responseType && responseType !== 'json') {
|
|---|
| 4239 | request.responseType = _config.responseType;
|
|---|
| 4240 | }
|
|---|
| 4241 |
|
|---|
| 4242 | // Handle progress if needed
|
|---|
| 4243 | if (onDownloadProgress) {
|
|---|
| 4244 | [downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true);
|
|---|
| 4245 | request.addEventListener('progress', downloadThrottled);
|
|---|
| 4246 | }
|
|---|
| 4247 |
|
|---|
| 4248 | // Not all browsers support upload events
|
|---|
| 4249 | if (onUploadProgress && request.upload) {
|
|---|
| 4250 | [uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress);
|
|---|
| 4251 | request.upload.addEventListener('progress', uploadThrottled);
|
|---|
| 4252 | request.upload.addEventListener('loadend', flushUpload);
|
|---|
| 4253 | }
|
|---|
| 4254 | if (_config.cancelToken || _config.signal) {
|
|---|
| 4255 | // Handle cancellation
|
|---|
| 4256 | // eslint-disable-next-line func-names
|
|---|
| 4257 | onCanceled = cancel => {
|
|---|
| 4258 | if (!request) {
|
|---|
| 4259 | return;
|
|---|
| 4260 | }
|
|---|
| 4261 | reject(!cancel || cancel.type ? new CanceledError(null, config, request) : cancel);
|
|---|
| 4262 | request.abort();
|
|---|
| 4263 | done();
|
|---|
| 4264 | request = null;
|
|---|
| 4265 | };
|
|---|
| 4266 | _config.cancelToken && _config.cancelToken.subscribe(onCanceled);
|
|---|
| 4267 | if (_config.signal) {
|
|---|
| 4268 | _config.signal.aborted ? onCanceled() : _config.signal.addEventListener('abort', onCanceled);
|
|---|
| 4269 | }
|
|---|
| 4270 | }
|
|---|
| 4271 | const protocol = parseProtocol(_config.url);
|
|---|
| 4272 | if (protocol && !platform.protocols.includes(protocol)) {
|
|---|
| 4273 | reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
|
|---|
| 4274 | return;
|
|---|
| 4275 | }
|
|---|
| 4276 |
|
|---|
| 4277 | // Send the request
|
|---|
| 4278 | request.send(requestData || null);
|
|---|
| 4279 | });
|
|---|
| 4280 | };
|
|---|
| 4281 |
|
|---|
| 4282 | const composeSignals = (signals, timeout) => {
|
|---|
| 4283 | signals = signals ? signals.filter(Boolean) : [];
|
|---|
| 4284 | if (!timeout && !signals.length) {
|
|---|
| 4285 | return;
|
|---|
| 4286 | }
|
|---|
| 4287 | const controller = new AbortController();
|
|---|
| 4288 | let aborted = false;
|
|---|
| 4289 | const onabort = function (reason) {
|
|---|
| 4290 | if (!aborted) {
|
|---|
| 4291 | aborted = true;
|
|---|
| 4292 | unsubscribe();
|
|---|
| 4293 | const err = reason instanceof Error ? reason : this.reason;
|
|---|
| 4294 | controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
|
|---|
| 4295 | }
|
|---|
| 4296 | };
|
|---|
| 4297 | let timer = timeout && setTimeout(() => {
|
|---|
| 4298 | timer = null;
|
|---|
| 4299 | onabort(new AxiosError(`timeout of ${timeout}ms exceeded`, AxiosError.ETIMEDOUT));
|
|---|
| 4300 | }, timeout);
|
|---|
| 4301 | const unsubscribe = () => {
|
|---|
| 4302 | if (!signals) {
|
|---|
| 4303 | return;
|
|---|
| 4304 | }
|
|---|
| 4305 | timer && clearTimeout(timer);
|
|---|
| 4306 | timer = null;
|
|---|
| 4307 | signals.forEach(signal => {
|
|---|
| 4308 | signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
|
|---|
| 4309 | });
|
|---|
| 4310 | signals = null;
|
|---|
| 4311 | };
|
|---|
| 4312 | signals.forEach(signal => signal.addEventListener('abort', onabort));
|
|---|
| 4313 | const {
|
|---|
| 4314 | signal
|
|---|
| 4315 | } = controller;
|
|---|
| 4316 | signal.unsubscribe = () => utils$1.asap(unsubscribe);
|
|---|
| 4317 | return signal;
|
|---|
| 4318 | };
|
|---|
| 4319 |
|
|---|
| 4320 | const streamChunk = function* (chunk, chunkSize) {
|
|---|
| 4321 | let len = chunk.byteLength;
|
|---|
| 4322 | if (len < chunkSize) {
|
|---|
| 4323 | yield chunk;
|
|---|
| 4324 | return;
|
|---|
| 4325 | }
|
|---|
| 4326 | let pos = 0;
|
|---|
| 4327 | let end;
|
|---|
| 4328 | while (pos < len) {
|
|---|
| 4329 | end = pos + chunkSize;
|
|---|
| 4330 | yield chunk.slice(pos, end);
|
|---|
| 4331 | pos = end;
|
|---|
| 4332 | }
|
|---|
| 4333 | };
|
|---|
| 4334 | const readBytes = async function* (iterable, chunkSize) {
|
|---|
| 4335 | for await (const chunk of readStream(iterable)) {
|
|---|
| 4336 | yield* streamChunk(chunk, chunkSize);
|
|---|
| 4337 | }
|
|---|
| 4338 | };
|
|---|
| 4339 | const readStream = async function* (stream) {
|
|---|
| 4340 | if (stream[Symbol.asyncIterator]) {
|
|---|
| 4341 | yield* stream;
|
|---|
| 4342 | return;
|
|---|
| 4343 | }
|
|---|
| 4344 | const reader = stream.getReader();
|
|---|
| 4345 | try {
|
|---|
| 4346 | for (;;) {
|
|---|
| 4347 | const {
|
|---|
| 4348 | done,
|
|---|
| 4349 | value
|
|---|
| 4350 | } = await reader.read();
|
|---|
| 4351 | if (done) {
|
|---|
| 4352 | break;
|
|---|
| 4353 | }
|
|---|
| 4354 | yield value;
|
|---|
| 4355 | }
|
|---|
| 4356 | } finally {
|
|---|
| 4357 | await reader.cancel();
|
|---|
| 4358 | }
|
|---|
| 4359 | };
|
|---|
| 4360 | const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
|---|
| 4361 | const iterator = readBytes(stream, chunkSize);
|
|---|
| 4362 | let bytes = 0;
|
|---|
| 4363 | let done;
|
|---|
| 4364 | let _onFinish = e => {
|
|---|
| 4365 | if (!done) {
|
|---|
| 4366 | done = true;
|
|---|
| 4367 | onFinish && onFinish(e);
|
|---|
| 4368 | }
|
|---|
| 4369 | };
|
|---|
| 4370 | return new ReadableStream({
|
|---|
| 4371 | async pull(controller) {
|
|---|
| 4372 | try {
|
|---|
| 4373 | const {
|
|---|
| 4374 | done,
|
|---|
| 4375 | value
|
|---|
| 4376 | } = await iterator.next();
|
|---|
| 4377 | if (done) {
|
|---|
| 4378 | _onFinish();
|
|---|
| 4379 | controller.close();
|
|---|
| 4380 | return;
|
|---|
| 4381 | }
|
|---|
| 4382 | let len = value.byteLength;
|
|---|
| 4383 | if (onProgress) {
|
|---|
| 4384 | let loadedBytes = bytes += len;
|
|---|
| 4385 | onProgress(loadedBytes);
|
|---|
| 4386 | }
|
|---|
| 4387 | controller.enqueue(new Uint8Array(value));
|
|---|
| 4388 | } catch (err) {
|
|---|
| 4389 | _onFinish(err);
|
|---|
| 4390 | throw err;
|
|---|
| 4391 | }
|
|---|
| 4392 | },
|
|---|
| 4393 | cancel(reason) {
|
|---|
| 4394 | _onFinish(reason);
|
|---|
| 4395 | return iterator.return();
|
|---|
| 4396 | }
|
|---|
| 4397 | }, {
|
|---|
| 4398 | highWaterMark: 2
|
|---|
| 4399 | });
|
|---|
| 4400 | };
|
|---|
| 4401 |
|
|---|
| 4402 | const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|---|
| 4403 | const {
|
|---|
| 4404 | isFunction
|
|---|
| 4405 | } = utils$1;
|
|---|
| 4406 | const test = (fn, ...args) => {
|
|---|
| 4407 | try {
|
|---|
| 4408 | return !!fn(...args);
|
|---|
| 4409 | } catch (e) {
|
|---|
| 4410 | return false;
|
|---|
| 4411 | }
|
|---|
| 4412 | };
|
|---|
| 4413 | const factory = env => {
|
|---|
| 4414 | const globalObject = utils$1.global !== undefined && utils$1.global !== null ? utils$1.global : globalThis;
|
|---|
| 4415 | const {
|
|---|
| 4416 | ReadableStream,
|
|---|
| 4417 | TextEncoder
|
|---|
| 4418 | } = globalObject;
|
|---|
| 4419 | env = utils$1.merge.call({
|
|---|
| 4420 | skipUndefined: true
|
|---|
| 4421 | }, {
|
|---|
| 4422 | Request: globalObject.Request,
|
|---|
| 4423 | Response: globalObject.Response
|
|---|
| 4424 | }, env);
|
|---|
| 4425 | const {
|
|---|
| 4426 | fetch: envFetch,
|
|---|
| 4427 | Request,
|
|---|
| 4428 | Response
|
|---|
| 4429 | } = env;
|
|---|
| 4430 | const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function';
|
|---|
| 4431 | const isRequestSupported = isFunction(Request);
|
|---|
| 4432 | const isResponseSupported = isFunction(Response);
|
|---|
| 4433 | if (!isFetchSupported) {
|
|---|
| 4434 | return false;
|
|---|
| 4435 | }
|
|---|
| 4436 | const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream);
|
|---|
| 4437 | const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ? (encoder => str => encoder.encode(str))(new TextEncoder()) : async str => new Uint8Array(await new Request(str).arrayBuffer()));
|
|---|
| 4438 | const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
|---|
| 4439 | let duplexAccessed = false;
|
|---|
| 4440 | const request = new Request(platform.origin, {
|
|---|
| 4441 | body: new ReadableStream(),
|
|---|
| 4442 | method: 'POST',
|
|---|
| 4443 | get duplex() {
|
|---|
| 4444 | duplexAccessed = true;
|
|---|
| 4445 | return 'half';
|
|---|
| 4446 | }
|
|---|
| 4447 | });
|
|---|
| 4448 | const hasContentType = request.headers.has('Content-Type');
|
|---|
| 4449 | if (request.body != null) {
|
|---|
| 4450 | request.body.cancel();
|
|---|
| 4451 | }
|
|---|
| 4452 | return duplexAccessed && !hasContentType;
|
|---|
| 4453 | });
|
|---|
| 4454 | const supportsResponseStream = isResponseSupported && isReadableStreamSupported && test(() => utils$1.isReadableStream(new Response('').body));
|
|---|
| 4455 | const resolvers = {
|
|---|
| 4456 | stream: supportsResponseStream && (res => res.body)
|
|---|
| 4457 | };
|
|---|
| 4458 | isFetchSupported && (() => {
|
|---|
| 4459 | ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
|---|
| 4460 | !resolvers[type] && (resolvers[type] = (res, config) => {
|
|---|
| 4461 | let method = res && res[type];
|
|---|
| 4462 | if (method) {
|
|---|
| 4463 | return method.call(res);
|
|---|
| 4464 | }
|
|---|
| 4465 | throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
|
|---|
| 4466 | });
|
|---|
| 4467 | });
|
|---|
| 4468 | })();
|
|---|
| 4469 | const getBodyLength = async body => {
|
|---|
| 4470 | if (body == null) {
|
|---|
| 4471 | return 0;
|
|---|
| 4472 | }
|
|---|
| 4473 | if (utils$1.isBlob(body)) {
|
|---|
| 4474 | return body.size;
|
|---|
| 4475 | }
|
|---|
| 4476 | if (utils$1.isSpecCompliantForm(body)) {
|
|---|
| 4477 | const _request = new Request(platform.origin, {
|
|---|
| 4478 | method: 'POST',
|
|---|
| 4479 | body
|
|---|
| 4480 | });
|
|---|
| 4481 | return (await _request.arrayBuffer()).byteLength;
|
|---|
| 4482 | }
|
|---|
| 4483 | if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
|---|
| 4484 | return body.byteLength;
|
|---|
| 4485 | }
|
|---|
| 4486 | if (utils$1.isURLSearchParams(body)) {
|
|---|
| 4487 | body = body + '';
|
|---|
| 4488 | }
|
|---|
| 4489 | if (utils$1.isString(body)) {
|
|---|
| 4490 | return (await encodeText(body)).byteLength;
|
|---|
| 4491 | }
|
|---|
| 4492 | };
|
|---|
| 4493 | const resolveBodyLength = async (headers, body) => {
|
|---|
| 4494 | const length = utils$1.toFiniteNumber(headers.getContentLength());
|
|---|
| 4495 | return length == null ? getBodyLength(body) : length;
|
|---|
| 4496 | };
|
|---|
| 4497 | return async config => {
|
|---|
| 4498 | let {
|
|---|
| 4499 | url,
|
|---|
| 4500 | method,
|
|---|
| 4501 | data,
|
|---|
| 4502 | signal,
|
|---|
| 4503 | cancelToken,
|
|---|
| 4504 | timeout,
|
|---|
| 4505 | onDownloadProgress,
|
|---|
| 4506 | onUploadProgress,
|
|---|
| 4507 | responseType,
|
|---|
| 4508 | headers,
|
|---|
| 4509 | withCredentials = 'same-origin',
|
|---|
| 4510 | fetchOptions,
|
|---|
| 4511 | maxContentLength,
|
|---|
| 4512 | maxBodyLength
|
|---|
| 4513 | } = resolveConfig(config);
|
|---|
| 4514 | const hasMaxContentLength = utils$1.isNumber(maxContentLength) && maxContentLength > -1;
|
|---|
| 4515 | const hasMaxBodyLength = utils$1.isNumber(maxBodyLength) && maxBodyLength > -1;
|
|---|
| 4516 | let _fetch = envFetch || fetch;
|
|---|
| 4517 | responseType = responseType ? (responseType + '').toLowerCase() : 'text';
|
|---|
| 4518 | let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
|---|
| 4519 | let request = null;
|
|---|
| 4520 | const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|---|
| 4521 | composedSignal.unsubscribe();
|
|---|
| 4522 | });
|
|---|
| 4523 | let requestContentLength;
|
|---|
| 4524 | try {
|
|---|
| 4525 | // Enforce maxContentLength for data: URLs up-front so we never materialize
|
|---|
| 4526 | // an oversized payload. The HTTP adapter applies the same check (see http.js
|
|---|
| 4527 | // "if (protocol === 'data:')" branch).
|
|---|
| 4528 | if (hasMaxContentLength && typeof url === 'string' && url.startsWith('data:')) {
|
|---|
| 4529 | const estimated = estimateDataURLDecodedBytes(url);
|
|---|
| 4530 | if (estimated > maxContentLength) {
|
|---|
| 4531 | throw new AxiosError('maxContentLength size of ' + maxContentLength + ' exceeded', AxiosError.ERR_BAD_RESPONSE, config, request);
|
|---|
| 4532 | }
|
|---|
| 4533 | }
|
|---|
| 4534 |
|
|---|
| 4535 | // Enforce maxBodyLength against the outbound request body before dispatch.
|
|---|
| 4536 | // Mirrors http.js behavior (ERR_BAD_REQUEST / 'Request body larger than
|
|---|
| 4537 | // maxBodyLength limit'). Skip when the body length cannot be determined
|
|---|
| 4538 | // (e.g. a live ReadableStream supplied by the caller).
|
|---|
| 4539 | if (hasMaxBodyLength && method !== 'get' && method !== 'head') {
|
|---|
| 4540 | const outboundLength = await resolveBodyLength(headers, data);
|
|---|
| 4541 | if (typeof outboundLength === 'number' && isFinite(outboundLength) && outboundLength > maxBodyLength) {
|
|---|
| 4542 | throw new AxiosError('Request body larger than maxBodyLength limit', AxiosError.ERR_BAD_REQUEST, config, request);
|
|---|
| 4543 | }
|
|---|
| 4544 | }
|
|---|
| 4545 | if (onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' && (requestContentLength = await resolveBodyLength(headers, data)) !== 0) {
|
|---|
| 4546 | let _request = new Request(url, {
|
|---|
| 4547 | method: 'POST',
|
|---|
| 4548 | body: data,
|
|---|
| 4549 | duplex: 'half'
|
|---|
| 4550 | });
|
|---|
| 4551 | let contentTypeHeader;
|
|---|
| 4552 | if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
|
|---|
| 4553 | headers.setContentType(contentTypeHeader);
|
|---|
| 4554 | }
|
|---|
| 4555 | if (_request.body) {
|
|---|
| 4556 | const [onProgress, flush] = progressEventDecorator(requestContentLength, progressEventReducer(asyncDecorator(onUploadProgress)));
|
|---|
| 4557 | data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
|---|
| 4558 | }
|
|---|
| 4559 | }
|
|---|
| 4560 | if (!utils$1.isString(withCredentials)) {
|
|---|
| 4561 | withCredentials = withCredentials ? 'include' : 'omit';
|
|---|
| 4562 | }
|
|---|
| 4563 |
|
|---|
| 4564 | // Cloudflare Workers throws when credentials are defined
|
|---|
| 4565 | // see https://github.com/cloudflare/workerd/issues/902
|
|---|
| 4566 | const isCredentialsSupported = isRequestSupported && 'credentials' in Request.prototype;
|
|---|
| 4567 |
|
|---|
| 4568 | // If data is FormData and Content-Type is multipart/form-data without boundary,
|
|---|
| 4569 | // delete it so fetch can set it correctly with the boundary
|
|---|
| 4570 | if (utils$1.isFormData(data)) {
|
|---|
| 4571 | const contentType = headers.getContentType();
|
|---|
| 4572 | if (contentType && /^multipart\/form-data/i.test(contentType) && !/boundary=/i.test(contentType)) {
|
|---|
| 4573 | headers.delete('content-type');
|
|---|
| 4574 | }
|
|---|
| 4575 | }
|
|---|
| 4576 |
|
|---|
| 4577 | // Set User-Agent header if not already set (fetch defaults to 'node' in Node.js)
|
|---|
| 4578 | headers.set('User-Agent', 'axios/' + VERSION, false);
|
|---|
| 4579 | const resolvedOptions = {
|
|---|
| 4580 | ...fetchOptions,
|
|---|
| 4581 | signal: composedSignal,
|
|---|
| 4582 | method: method.toUpperCase(),
|
|---|
| 4583 | headers: toByteStringHeaderObject(headers.normalize()),
|
|---|
| 4584 | body: data,
|
|---|
| 4585 | duplex: 'half',
|
|---|
| 4586 | credentials: isCredentialsSupported ? withCredentials : undefined
|
|---|
| 4587 | };
|
|---|
| 4588 | request = isRequestSupported && new Request(url, resolvedOptions);
|
|---|
| 4589 | let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
|
|---|
| 4590 |
|
|---|
| 4591 | // Cheap pre-check: if the server honestly declares a content-length that
|
|---|
| 4592 | // already exceeds the cap, reject before we start streaming.
|
|---|
| 4593 | if (hasMaxContentLength) {
|
|---|
| 4594 | const declaredLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
|---|
| 4595 | if (declaredLength != null && declaredLength > maxContentLength) {
|
|---|
| 4596 | throw new AxiosError('maxContentLength size of ' + maxContentLength + ' exceeded', AxiosError.ERR_BAD_RESPONSE, config, request);
|
|---|
| 4597 | }
|
|---|
| 4598 | }
|
|---|
| 4599 | const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
|
|---|
| 4600 | if (supportsResponseStream && response.body && (onDownloadProgress || hasMaxContentLength || isStreamResponse && unsubscribe)) {
|
|---|
| 4601 | const options = {};
|
|---|
| 4602 | ['status', 'statusText', 'headers'].forEach(prop => {
|
|---|
| 4603 | options[prop] = response[prop];
|
|---|
| 4604 | });
|
|---|
| 4605 | const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
|---|
| 4606 | const [onProgress, flush] = onDownloadProgress && progressEventDecorator(responseContentLength, progressEventReducer(asyncDecorator(onDownloadProgress), true)) || [];
|
|---|
| 4607 | let bytesRead = 0;
|
|---|
| 4608 | const onChunkProgress = loadedBytes => {
|
|---|
| 4609 | if (hasMaxContentLength) {
|
|---|
| 4610 | bytesRead = loadedBytes;
|
|---|
| 4611 | if (bytesRead > maxContentLength) {
|
|---|
| 4612 | throw new AxiosError('maxContentLength size of ' + maxContentLength + ' exceeded', AxiosError.ERR_BAD_RESPONSE, config, request);
|
|---|
| 4613 | }
|
|---|
| 4614 | }
|
|---|
| 4615 | onProgress && onProgress(loadedBytes);
|
|---|
| 4616 | };
|
|---|
| 4617 | response = new Response(trackStream(response.body, DEFAULT_CHUNK_SIZE, onChunkProgress, () => {
|
|---|
| 4618 | flush && flush();
|
|---|
| 4619 | unsubscribe && unsubscribe();
|
|---|
| 4620 | }), options);
|
|---|
| 4621 | }
|
|---|
| 4622 | responseType = responseType || 'text';
|
|---|
| 4623 | let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
|
|---|
| 4624 |
|
|---|
| 4625 | // Fallback enforcement for environments without ReadableStream support
|
|---|
| 4626 | // (legacy runtimes). Detect materialized size from typed output; skip
|
|---|
| 4627 | // streams/Response passthrough since the user will read those themselves.
|
|---|
| 4628 | if (hasMaxContentLength && !supportsResponseStream && !isStreamResponse) {
|
|---|
| 4629 | let materializedSize;
|
|---|
| 4630 | if (responseData != null) {
|
|---|
| 4631 | if (typeof responseData.byteLength === 'number') {
|
|---|
| 4632 | materializedSize = responseData.byteLength;
|
|---|
| 4633 | } else if (typeof responseData.size === 'number') {
|
|---|
| 4634 | materializedSize = responseData.size;
|
|---|
| 4635 | } else if (typeof responseData === 'string') {
|
|---|
| 4636 | materializedSize = typeof TextEncoder === 'function' ? new TextEncoder().encode(responseData).byteLength : responseData.length;
|
|---|
| 4637 | }
|
|---|
| 4638 | }
|
|---|
| 4639 | if (typeof materializedSize === 'number' && materializedSize > maxContentLength) {
|
|---|
| 4640 | throw new AxiosError('maxContentLength size of ' + maxContentLength + ' exceeded', AxiosError.ERR_BAD_RESPONSE, config, request);
|
|---|
| 4641 | }
|
|---|
| 4642 | }
|
|---|
| 4643 | !isStreamResponse && unsubscribe && unsubscribe();
|
|---|
| 4644 | return await new Promise((resolve, reject) => {
|
|---|
| 4645 | settle(resolve, reject, {
|
|---|
| 4646 | data: responseData,
|
|---|
| 4647 | headers: AxiosHeaders.from(response.headers),
|
|---|
| 4648 | status: response.status,
|
|---|
| 4649 | statusText: response.statusText,
|
|---|
| 4650 | config,
|
|---|
| 4651 | request
|
|---|
| 4652 | });
|
|---|
| 4653 | });
|
|---|
| 4654 | } catch (err) {
|
|---|
| 4655 | unsubscribe && unsubscribe();
|
|---|
| 4656 |
|
|---|
| 4657 | // Safari can surface fetch aborts as a DOMException-like object whose
|
|---|
| 4658 | // branded getters throw. Prefer our composed signal reason before reading
|
|---|
| 4659 | // the caught error, preserving timeout vs cancellation semantics.
|
|---|
| 4660 | if (composedSignal && composedSignal.aborted && composedSignal.reason instanceof AxiosError) {
|
|---|
| 4661 | const canceledError = composedSignal.reason;
|
|---|
| 4662 | canceledError.config = config;
|
|---|
| 4663 | request && (canceledError.request = request);
|
|---|
| 4664 | err !== canceledError && (canceledError.cause = err);
|
|---|
| 4665 | throw canceledError;
|
|---|
| 4666 | }
|
|---|
| 4667 | if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
|
|---|
| 4668 | throw Object.assign(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request, err && err.response), {
|
|---|
| 4669 | cause: err.cause || err
|
|---|
| 4670 | });
|
|---|
| 4671 | }
|
|---|
| 4672 | throw AxiosError.from(err, err && err.code, config, request, err && err.response);
|
|---|
| 4673 | }
|
|---|
| 4674 | };
|
|---|
| 4675 | };
|
|---|
| 4676 | const seedCache = new Map();
|
|---|
| 4677 | const getFetch = config => {
|
|---|
| 4678 | let env = config && config.env || {};
|
|---|
| 4679 | const {
|
|---|
| 4680 | fetch,
|
|---|
| 4681 | Request,
|
|---|
| 4682 | Response
|
|---|
| 4683 | } = env;
|
|---|
| 4684 | const seeds = [Request, Response, fetch];
|
|---|
| 4685 | let len = seeds.length,
|
|---|
| 4686 | i = len,
|
|---|
| 4687 | seed,
|
|---|
| 4688 | target,
|
|---|
| 4689 | map = seedCache;
|
|---|
| 4690 | while (i--) {
|
|---|
| 4691 | seed = seeds[i];
|
|---|
| 4692 | target = map.get(seed);
|
|---|
| 4693 | target === undefined && map.set(seed, target = i ? new Map() : factory(env));
|
|---|
| 4694 | map = target;
|
|---|
| 4695 | }
|
|---|
| 4696 | return target;
|
|---|
| 4697 | };
|
|---|
| 4698 | getFetch();
|
|---|
| 4699 |
|
|---|
| 4700 | /**
|
|---|
| 4701 | * Known adapters mapping.
|
|---|
| 4702 | * Provides environment-specific adapters for Axios:
|
|---|
| 4703 | * - `http` for Node.js
|
|---|
| 4704 | * - `xhr` for browsers
|
|---|
| 4705 | * - `fetch` for fetch API-based requests
|
|---|
| 4706 | *
|
|---|
| 4707 | * @type {Object<string, Function|Object>}
|
|---|
| 4708 | */
|
|---|
| 4709 | const knownAdapters = {
|
|---|
| 4710 | http: httpAdapter,
|
|---|
| 4711 | xhr: xhrAdapter,
|
|---|
| 4712 | fetch: {
|
|---|
| 4713 | get: getFetch
|
|---|
| 4714 | }
|
|---|
| 4715 | };
|
|---|
| 4716 |
|
|---|
| 4717 | // Assign adapter names for easier debugging and identification
|
|---|
| 4718 | utils$1.forEach(knownAdapters, (fn, value) => {
|
|---|
| 4719 | if (fn) {
|
|---|
| 4720 | try {
|
|---|
| 4721 | // Null-proto descriptors so a polluted Object.prototype.get cannot turn
|
|---|
| 4722 | // these data descriptors into accessor descriptors on the way in.
|
|---|
| 4723 | Object.defineProperty(fn, 'name', {
|
|---|
| 4724 | __proto__: null,
|
|---|
| 4725 | value
|
|---|
| 4726 | });
|
|---|
| 4727 | } catch (e) {
|
|---|
| 4728 | // eslint-disable-next-line no-empty
|
|---|
| 4729 | }
|
|---|
| 4730 | Object.defineProperty(fn, 'adapterName', {
|
|---|
| 4731 | __proto__: null,
|
|---|
| 4732 | value
|
|---|
| 4733 | });
|
|---|
| 4734 | }
|
|---|
| 4735 | });
|
|---|
| 4736 |
|
|---|
| 4737 | /**
|
|---|
| 4738 | * Render a rejection reason string for unknown or unsupported adapters
|
|---|
| 4739 | *
|
|---|
| 4740 | * @param {string} reason
|
|---|
| 4741 | * @returns {string}
|
|---|
| 4742 | */
|
|---|
| 4743 | const renderReason = reason => `- ${reason}`;
|
|---|
| 4744 |
|
|---|
| 4745 | /**
|
|---|
| 4746 | * Check if the adapter is resolved (function, null, or false)
|
|---|
| 4747 | *
|
|---|
| 4748 | * @param {Function|null|false} adapter
|
|---|
| 4749 | * @returns {boolean}
|
|---|
| 4750 | */
|
|---|
| 4751 | const isResolvedHandle = adapter => utils$1.isFunction(adapter) || adapter === null || adapter === false;
|
|---|
| 4752 |
|
|---|
| 4753 | /**
|
|---|
| 4754 | * Get the first suitable adapter from the provided list.
|
|---|
| 4755 | * Tries each adapter in order until a supported one is found.
|
|---|
| 4756 | * Throws an AxiosError if no adapter is suitable.
|
|---|
| 4757 | *
|
|---|
| 4758 | * @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function.
|
|---|
| 4759 | * @param {Object} config - Axios request configuration
|
|---|
| 4760 | * @throws {AxiosError} If no suitable adapter is available
|
|---|
| 4761 | * @returns {Function} The resolved adapter function
|
|---|
| 4762 | */
|
|---|
| 4763 | function getAdapter(adapters, config) {
|
|---|
| 4764 | adapters = utils$1.isArray(adapters) ? adapters : [adapters];
|
|---|
| 4765 | const {
|
|---|
| 4766 | length
|
|---|
| 4767 | } = adapters;
|
|---|
| 4768 | let nameOrAdapter;
|
|---|
| 4769 | let adapter;
|
|---|
| 4770 | const rejectedReasons = {};
|
|---|
| 4771 | for (let i = 0; i < length; i++) {
|
|---|
| 4772 | nameOrAdapter = adapters[i];
|
|---|
| 4773 | let id;
|
|---|
| 4774 | adapter = nameOrAdapter;
|
|---|
| 4775 | if (!isResolvedHandle(nameOrAdapter)) {
|
|---|
| 4776 | adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
|---|
| 4777 | if (adapter === undefined) {
|
|---|
| 4778 | throw new AxiosError(`Unknown adapter '${id}'`);
|
|---|
| 4779 | }
|
|---|
| 4780 | }
|
|---|
| 4781 | if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
|
|---|
| 4782 | break;
|
|---|
| 4783 | }
|
|---|
| 4784 | rejectedReasons[id || '#' + i] = adapter;
|
|---|
| 4785 | }
|
|---|
| 4786 | if (!adapter) {
|
|---|
| 4787 | const reasons = Object.entries(rejectedReasons).map(([id, state]) => `adapter ${id} ` + (state === false ? 'is not supported by the environment' : 'is not available in the build'));
|
|---|
| 4788 | let s = length ? reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0]) : 'as no adapter specified';
|
|---|
| 4789 | throw new AxiosError(`There is no suitable adapter to dispatch the request ` + s, 'ERR_NOT_SUPPORT');
|
|---|
| 4790 | }
|
|---|
| 4791 | return adapter;
|
|---|
| 4792 | }
|
|---|
| 4793 |
|
|---|
| 4794 | /**
|
|---|
| 4795 | * Exports Axios adapters and utility to resolve an adapter
|
|---|
| 4796 | */
|
|---|
| 4797 | var adapters = {
|
|---|
| 4798 | /**
|
|---|
| 4799 | * Resolve an adapter from a list of adapter names or functions.
|
|---|
| 4800 | * @type {Function}
|
|---|
| 4801 | */
|
|---|
| 4802 | getAdapter,
|
|---|
| 4803 | /**
|
|---|
| 4804 | * Exposes all known adapters
|
|---|
| 4805 | * @type {Object<string, Function|Object>}
|
|---|
| 4806 | */
|
|---|
| 4807 | adapters: knownAdapters
|
|---|
| 4808 | };
|
|---|
| 4809 |
|
|---|
| 4810 | /**
|
|---|
| 4811 | * Throws a `CanceledError` if cancellation has been requested.
|
|---|
| 4812 | *
|
|---|
| 4813 | * @param {Object} config The config that is to be used for the request
|
|---|
| 4814 | *
|
|---|
| 4815 | * @returns {void}
|
|---|
| 4816 | */
|
|---|
| 4817 | function throwIfCancellationRequested(config) {
|
|---|
| 4818 | if (config.cancelToken) {
|
|---|
| 4819 | config.cancelToken.throwIfRequested();
|
|---|
| 4820 | }
|
|---|
| 4821 | if (config.signal && config.signal.aborted) {
|
|---|
| 4822 | throw new CanceledError(null, config);
|
|---|
| 4823 | }
|
|---|
| 4824 | }
|
|---|
| 4825 |
|
|---|
| 4826 | /**
|
|---|
| 4827 | * Dispatch a request to the server using the configured adapter.
|
|---|
| 4828 | *
|
|---|
| 4829 | * @param {object} config The config that is to be used for the request
|
|---|
| 4830 | *
|
|---|
| 4831 | * @returns {Promise} The Promise to be fulfilled
|
|---|
| 4832 | */
|
|---|
| 4833 | function dispatchRequest(config) {
|
|---|
| 4834 | throwIfCancellationRequested(config);
|
|---|
| 4835 | config.headers = AxiosHeaders.from(config.headers);
|
|---|
| 4836 |
|
|---|
| 4837 | // Transform request data
|
|---|
| 4838 | config.data = transformData.call(config, config.transformRequest);
|
|---|
| 4839 | if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
|
|---|
| 4840 | config.headers.setContentType('application/x-www-form-urlencoded', false);
|
|---|
| 4841 | }
|
|---|
| 4842 | const adapter = adapters.getAdapter(config.adapter || defaults.adapter, config);
|
|---|
| 4843 | return adapter(config).then(function onAdapterResolution(response) {
|
|---|
| 4844 | throwIfCancellationRequested(config);
|
|---|
| 4845 |
|
|---|
| 4846 | // Expose the current response on config so that transformResponse can
|
|---|
| 4847 | // attach it to any AxiosError it throws (e.g. on JSON parse failure).
|
|---|
| 4848 | // We clean it up afterwards to avoid polluting the config object.
|
|---|
| 4849 | config.response = response;
|
|---|
| 4850 | try {
|
|---|
| 4851 | response.data = transformData.call(config, config.transformResponse, response);
|
|---|
| 4852 | } finally {
|
|---|
| 4853 | delete config.response;
|
|---|
| 4854 | }
|
|---|
| 4855 | response.headers = AxiosHeaders.from(response.headers);
|
|---|
| 4856 | return response;
|
|---|
| 4857 | }, function onAdapterRejection(reason) {
|
|---|
| 4858 | if (!isCancel(reason)) {
|
|---|
| 4859 | throwIfCancellationRequested(config);
|
|---|
| 4860 |
|
|---|
| 4861 | // Transform response data
|
|---|
| 4862 | if (reason && reason.response) {
|
|---|
| 4863 | config.response = reason.response;
|
|---|
| 4864 | try {
|
|---|
| 4865 | reason.response.data = transformData.call(config, config.transformResponse, reason.response);
|
|---|
| 4866 | } finally {
|
|---|
| 4867 | delete config.response;
|
|---|
| 4868 | }
|
|---|
| 4869 | reason.response.headers = AxiosHeaders.from(reason.response.headers);
|
|---|
| 4870 | }
|
|---|
| 4871 | }
|
|---|
| 4872 | return Promise.reject(reason);
|
|---|
| 4873 | });
|
|---|
| 4874 | }
|
|---|
| 4875 |
|
|---|
| 4876 | const validators$1 = {};
|
|---|
| 4877 |
|
|---|
| 4878 | // eslint-disable-next-line func-names
|
|---|
| 4879 | ['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach((type, i) => {
|
|---|
| 4880 | validators$1[type] = function validator(thing) {
|
|---|
| 4881 | return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
|
|---|
| 4882 | };
|
|---|
| 4883 | });
|
|---|
| 4884 | const deprecatedWarnings = {};
|
|---|
| 4885 |
|
|---|
| 4886 | /**
|
|---|
| 4887 | * Transitional option validator
|
|---|
| 4888 | *
|
|---|
| 4889 | * @param {function|boolean?} validator - set to false if the transitional option has been removed
|
|---|
| 4890 | * @param {string?} version - deprecated version / removed since version
|
|---|
| 4891 | * @param {string?} message - some message with additional info
|
|---|
| 4892 | *
|
|---|
| 4893 | * @returns {function}
|
|---|
| 4894 | */
|
|---|
| 4895 | validators$1.transitional = function transitional(validator, version, message) {
|
|---|
| 4896 | function formatMessage(opt, desc) {
|
|---|
| 4897 | return '[Axios v' + VERSION + "] Transitional option '" + opt + "'" + desc + (message ? '. ' + message : '');
|
|---|
| 4898 | }
|
|---|
| 4899 |
|
|---|
| 4900 | // eslint-disable-next-line func-names
|
|---|
| 4901 | return (value, opt, opts) => {
|
|---|
| 4902 | if (validator === false) {
|
|---|
| 4903 | throw new AxiosError(formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')), AxiosError.ERR_DEPRECATED);
|
|---|
| 4904 | }
|
|---|
| 4905 | if (version && !deprecatedWarnings[opt]) {
|
|---|
| 4906 | deprecatedWarnings[opt] = true;
|
|---|
| 4907 | // eslint-disable-next-line no-console
|
|---|
| 4908 | console.warn(formatMessage(opt, ' has been deprecated since v' + version + ' and will be removed in the near future'));
|
|---|
| 4909 | }
|
|---|
| 4910 | return validator ? validator(value, opt, opts) : true;
|
|---|
| 4911 | };
|
|---|
| 4912 | };
|
|---|
| 4913 | validators$1.spelling = function spelling(correctSpelling) {
|
|---|
| 4914 | return (value, opt) => {
|
|---|
| 4915 | // eslint-disable-next-line no-console
|
|---|
| 4916 | console.warn(`${opt} is likely a misspelling of ${correctSpelling}`);
|
|---|
| 4917 | return true;
|
|---|
| 4918 | };
|
|---|
| 4919 | };
|
|---|
| 4920 |
|
|---|
| 4921 | /**
|
|---|
| 4922 | * Assert object's properties type
|
|---|
| 4923 | *
|
|---|
| 4924 | * @param {object} options
|
|---|
| 4925 | * @param {object} schema
|
|---|
| 4926 | * @param {boolean?} allowUnknown
|
|---|
| 4927 | *
|
|---|
| 4928 | * @returns {object}
|
|---|
| 4929 | */
|
|---|
| 4930 |
|
|---|
| 4931 | function assertOptions(options, schema, allowUnknown) {
|
|---|
| 4932 | if (typeof options !== 'object') {
|
|---|
| 4933 | throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE);
|
|---|
| 4934 | }
|
|---|
| 4935 | const keys = Object.keys(options);
|
|---|
| 4936 | let i = keys.length;
|
|---|
| 4937 | while (i-- > 0) {
|
|---|
| 4938 | const opt = keys[i];
|
|---|
| 4939 | // Use hasOwnProperty so a polluted Object.prototype.<opt> cannot supply
|
|---|
| 4940 | // a non-function validator and cause a TypeError.
|
|---|
| 4941 | const validator = Object.prototype.hasOwnProperty.call(schema, opt) ? schema[opt] : undefined;
|
|---|
| 4942 | if (validator) {
|
|---|
| 4943 | const value = options[opt];
|
|---|
| 4944 | const result = value === undefined || validator(value, opt, options);
|
|---|
| 4945 | if (result !== true) {
|
|---|
| 4946 | throw new AxiosError('option ' + opt + ' must be ' + result, AxiosError.ERR_BAD_OPTION_VALUE);
|
|---|
| 4947 | }
|
|---|
| 4948 | continue;
|
|---|
| 4949 | }
|
|---|
| 4950 | if (allowUnknown !== true) {
|
|---|
| 4951 | throw new AxiosError('Unknown option ' + opt, AxiosError.ERR_BAD_OPTION);
|
|---|
| 4952 | }
|
|---|
| 4953 | }
|
|---|
| 4954 | }
|
|---|
| 4955 | var validator = {
|
|---|
| 4956 | assertOptions,
|
|---|
| 4957 | validators: validators$1
|
|---|
| 4958 | };
|
|---|
| 4959 |
|
|---|
| 4960 | const validators = validator.validators;
|
|---|
| 4961 |
|
|---|
| 4962 | /**
|
|---|
| 4963 | * Create a new instance of Axios
|
|---|
| 4964 | *
|
|---|
| 4965 | * @param {Object} instanceConfig The default config for the instance
|
|---|
| 4966 | *
|
|---|
| 4967 | * @return {Axios} A new instance of Axios
|
|---|
| 4968 | */
|
|---|
| 4969 | class Axios {
|
|---|
| 4970 | constructor(instanceConfig) {
|
|---|
| 4971 | this.defaults = instanceConfig || {};
|
|---|
| 4972 | this.interceptors = {
|
|---|
| 4973 | request: new InterceptorManager(),
|
|---|
| 4974 | response: new InterceptorManager()
|
|---|
| 4975 | };
|
|---|
| 4976 | }
|
|---|
| 4977 |
|
|---|
| 4978 | /**
|
|---|
| 4979 | * Dispatch a request
|
|---|
| 4980 | *
|
|---|
| 4981 | * @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
|
|---|
| 4982 | * @param {?Object} config
|
|---|
| 4983 | *
|
|---|
| 4984 | * @returns {Promise} The Promise to be fulfilled
|
|---|
| 4985 | */
|
|---|
| 4986 | async request(configOrUrl, config) {
|
|---|
| 4987 | try {
|
|---|
| 4988 | return await this._request(configOrUrl, config);
|
|---|
| 4989 | } catch (err) {
|
|---|
| 4990 | if (err instanceof Error) {
|
|---|
| 4991 | let dummy = {};
|
|---|
| 4992 | Error.captureStackTrace ? Error.captureStackTrace(dummy) : dummy = new Error();
|
|---|
| 4993 |
|
|---|
| 4994 | // slice off the Error: ... line
|
|---|
| 4995 | const stack = (() => {
|
|---|
| 4996 | if (!dummy.stack) {
|
|---|
| 4997 | return '';
|
|---|
| 4998 | }
|
|---|
| 4999 | const firstNewlineIndex = dummy.stack.indexOf('\n');
|
|---|
| 5000 | return firstNewlineIndex === -1 ? '' : dummy.stack.slice(firstNewlineIndex + 1);
|
|---|
| 5001 | })();
|
|---|
| 5002 | try {
|
|---|
| 5003 | if (!err.stack) {
|
|---|
| 5004 | err.stack = stack;
|
|---|
| 5005 | // match without the 2 top stack lines
|
|---|
| 5006 | } else if (stack) {
|
|---|
| 5007 | const firstNewlineIndex = stack.indexOf('\n');
|
|---|
| 5008 | const secondNewlineIndex = firstNewlineIndex === -1 ? -1 : stack.indexOf('\n', firstNewlineIndex + 1);
|
|---|
| 5009 | const stackWithoutTwoTopLines = secondNewlineIndex === -1 ? '' : stack.slice(secondNewlineIndex + 1);
|
|---|
| 5010 | if (!String(err.stack).endsWith(stackWithoutTwoTopLines)) {
|
|---|
| 5011 | err.stack += '\n' + stack;
|
|---|
| 5012 | }
|
|---|
| 5013 | }
|
|---|
| 5014 | } catch (e) {
|
|---|
| 5015 | // ignore the case where "stack" is an un-writable property
|
|---|
| 5016 | }
|
|---|
| 5017 | }
|
|---|
| 5018 | throw err;
|
|---|
| 5019 | }
|
|---|
| 5020 | }
|
|---|
| 5021 | _request(configOrUrl, config) {
|
|---|
| 5022 | /*eslint no-param-reassign:0*/
|
|---|
| 5023 | // Allow for axios('example/url'[, config]) a la fetch API
|
|---|
| 5024 | if (typeof configOrUrl === 'string') {
|
|---|
| 5025 | config = config || {};
|
|---|
| 5026 | config.url = configOrUrl;
|
|---|
| 5027 | } else {
|
|---|
| 5028 | config = configOrUrl || {};
|
|---|
| 5029 | }
|
|---|
| 5030 | config = mergeConfig(this.defaults, config);
|
|---|
| 5031 | const {
|
|---|
| 5032 | transitional,
|
|---|
| 5033 | paramsSerializer,
|
|---|
| 5034 | headers
|
|---|
| 5035 | } = config;
|
|---|
| 5036 | if (transitional !== undefined) {
|
|---|
| 5037 | validator.assertOptions(transitional, {
|
|---|
| 5038 | silentJSONParsing: validators.transitional(validators.boolean),
|
|---|
| 5039 | forcedJSONParsing: validators.transitional(validators.boolean),
|
|---|
| 5040 | clarifyTimeoutError: validators.transitional(validators.boolean),
|
|---|
| 5041 | legacyInterceptorReqResOrdering: validators.transitional(validators.boolean)
|
|---|
| 5042 | }, false);
|
|---|
| 5043 | }
|
|---|
| 5044 | if (paramsSerializer != null) {
|
|---|
| 5045 | if (utils$1.isFunction(paramsSerializer)) {
|
|---|
| 5046 | config.paramsSerializer = {
|
|---|
| 5047 | serialize: paramsSerializer
|
|---|
| 5048 | };
|
|---|
| 5049 | } else {
|
|---|
| 5050 | validator.assertOptions(paramsSerializer, {
|
|---|
| 5051 | encode: validators.function,
|
|---|
| 5052 | serialize: validators.function
|
|---|
| 5053 | }, true);
|
|---|
| 5054 | }
|
|---|
| 5055 | }
|
|---|
| 5056 |
|
|---|
| 5057 | // Set config.allowAbsoluteUrls
|
|---|
| 5058 | if (config.allowAbsoluteUrls !== undefined) ; else if (this.defaults.allowAbsoluteUrls !== undefined) {
|
|---|
| 5059 | config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
|
|---|
| 5060 | } else {
|
|---|
| 5061 | config.allowAbsoluteUrls = true;
|
|---|
| 5062 | }
|
|---|
| 5063 | validator.assertOptions(config, {
|
|---|
| 5064 | baseUrl: validators.spelling('baseURL'),
|
|---|
| 5065 | withXsrfToken: validators.spelling('withXSRFToken')
|
|---|
| 5066 | }, true);
|
|---|
| 5067 |
|
|---|
| 5068 | // Set config.method
|
|---|
| 5069 | config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
|---|
| 5070 |
|
|---|
| 5071 | // Flatten headers
|
|---|
| 5072 | let contextHeaders = headers && utils$1.merge(headers.common, headers[config.method]);
|
|---|
| 5073 | headers && utils$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'query', 'common'], method => {
|
|---|
| 5074 | delete headers[method];
|
|---|
| 5075 | });
|
|---|
| 5076 | config.headers = AxiosHeaders.concat(contextHeaders, headers);
|
|---|
| 5077 |
|
|---|
| 5078 | // filter out skipped interceptors
|
|---|
| 5079 | const requestInterceptorChain = [];
|
|---|
| 5080 | let synchronousRequestInterceptors = true;
|
|---|
| 5081 | this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
|---|
| 5082 | if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
|
|---|
| 5083 | return;
|
|---|
| 5084 | }
|
|---|
| 5085 | synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
|---|
| 5086 | const transitional = config.transitional || transitionalDefaults;
|
|---|
| 5087 | const legacyInterceptorReqResOrdering = transitional && transitional.legacyInterceptorReqResOrdering;
|
|---|
| 5088 | if (legacyInterceptorReqResOrdering) {
|
|---|
| 5089 | requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
|---|
| 5090 | } else {
|
|---|
| 5091 | requestInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
|---|
| 5092 | }
|
|---|
| 5093 | });
|
|---|
| 5094 | const responseInterceptorChain = [];
|
|---|
| 5095 | this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
|---|
| 5096 | responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
|---|
| 5097 | });
|
|---|
| 5098 | let promise;
|
|---|
| 5099 | let i = 0;
|
|---|
| 5100 | let len;
|
|---|
| 5101 | if (!synchronousRequestInterceptors) {
|
|---|
| 5102 | const chain = [dispatchRequest.bind(this), undefined];
|
|---|
| 5103 | chain.unshift(...requestInterceptorChain);
|
|---|
| 5104 | chain.push(...responseInterceptorChain);
|
|---|
| 5105 | len = chain.length;
|
|---|
| 5106 | promise = Promise.resolve(config);
|
|---|
| 5107 | while (i < len) {
|
|---|
| 5108 | promise = promise.then(chain[i++], chain[i++]);
|
|---|
| 5109 | }
|
|---|
| 5110 | return promise;
|
|---|
| 5111 | }
|
|---|
| 5112 | len = requestInterceptorChain.length;
|
|---|
| 5113 | let newConfig = config;
|
|---|
| 5114 | while (i < len) {
|
|---|
| 5115 | const onFulfilled = requestInterceptorChain[i++];
|
|---|
| 5116 | const onRejected = requestInterceptorChain[i++];
|
|---|
| 5117 | try {
|
|---|
| 5118 | newConfig = onFulfilled(newConfig);
|
|---|
| 5119 | } catch (error) {
|
|---|
| 5120 | onRejected.call(this, error);
|
|---|
| 5121 | break;
|
|---|
| 5122 | }
|
|---|
| 5123 | }
|
|---|
| 5124 | try {
|
|---|
| 5125 | promise = dispatchRequest.call(this, newConfig);
|
|---|
| 5126 | } catch (error) {
|
|---|
| 5127 | return Promise.reject(error);
|
|---|
| 5128 | }
|
|---|
| 5129 | i = 0;
|
|---|
| 5130 | len = responseInterceptorChain.length;
|
|---|
| 5131 | while (i < len) {
|
|---|
| 5132 | promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
|---|
| 5133 | }
|
|---|
| 5134 | return promise;
|
|---|
| 5135 | }
|
|---|
| 5136 | getUri(config) {
|
|---|
| 5137 | config = mergeConfig(this.defaults, config);
|
|---|
| 5138 | const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
|
|---|
| 5139 | return buildURL(fullPath, config.params, config.paramsSerializer);
|
|---|
| 5140 | }
|
|---|
| 5141 | }
|
|---|
| 5142 |
|
|---|
| 5143 | // Provide aliases for supported request methods
|
|---|
| 5144 | utils$1.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
|
|---|
| 5145 | /*eslint func-names:0*/
|
|---|
| 5146 | Axios.prototype[method] = function (url, config) {
|
|---|
| 5147 | return this.request(mergeConfig(config || {}, {
|
|---|
| 5148 | method,
|
|---|
| 5149 | url,
|
|---|
| 5150 | data: (config || {}).data
|
|---|
| 5151 | }));
|
|---|
| 5152 | };
|
|---|
| 5153 | });
|
|---|
| 5154 | utils$1.forEach(['post', 'put', 'patch', 'query'], function forEachMethodWithData(method) {
|
|---|
| 5155 | function generateHTTPMethod(isForm) {
|
|---|
| 5156 | return function httpMethod(url, data, config) {
|
|---|
| 5157 | return this.request(mergeConfig(config || {}, {
|
|---|
| 5158 | method,
|
|---|
| 5159 | headers: isForm ? {
|
|---|
| 5160 | 'Content-Type': 'multipart/form-data'
|
|---|
| 5161 | } : {},
|
|---|
| 5162 | url,
|
|---|
| 5163 | data
|
|---|
| 5164 | }));
|
|---|
| 5165 | };
|
|---|
| 5166 | }
|
|---|
| 5167 | Axios.prototype[method] = generateHTTPMethod();
|
|---|
| 5168 |
|
|---|
| 5169 | // QUERY is a safe/idempotent read method; multipart form bodies don't fit
|
|---|
| 5170 | // its semantics, so no queryForm shorthand is generated.
|
|---|
| 5171 | if (method !== 'query') {
|
|---|
| 5172 | Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
|---|
| 5173 | }
|
|---|
| 5174 | });
|
|---|
| 5175 |
|
|---|
| 5176 | /**
|
|---|
| 5177 | * A `CancelToken` is an object that can be used to request cancellation of an operation.
|
|---|
| 5178 | *
|
|---|
| 5179 | * @param {Function} executor The executor function.
|
|---|
| 5180 | *
|
|---|
| 5181 | * @returns {CancelToken}
|
|---|
| 5182 | */
|
|---|
| 5183 | class CancelToken {
|
|---|
| 5184 | constructor(executor) {
|
|---|
| 5185 | if (typeof executor !== 'function') {
|
|---|
| 5186 | throw new TypeError('executor must be a function.');
|
|---|
| 5187 | }
|
|---|
| 5188 | let resolvePromise;
|
|---|
| 5189 | this.promise = new Promise(function promiseExecutor(resolve) {
|
|---|
| 5190 | resolvePromise = resolve;
|
|---|
| 5191 | });
|
|---|
| 5192 | const token = this;
|
|---|
| 5193 |
|
|---|
| 5194 | // eslint-disable-next-line func-names
|
|---|
| 5195 | this.promise.then(cancel => {
|
|---|
| 5196 | if (!token._listeners) return;
|
|---|
| 5197 | let i = token._listeners.length;
|
|---|
| 5198 | while (i-- > 0) {
|
|---|
| 5199 | token._listeners[i](cancel);
|
|---|
| 5200 | }
|
|---|
| 5201 | token._listeners = null;
|
|---|
| 5202 | });
|
|---|
| 5203 |
|
|---|
| 5204 | // eslint-disable-next-line func-names
|
|---|
| 5205 | this.promise.then = onfulfilled => {
|
|---|
| 5206 | let _resolve;
|
|---|
| 5207 | // eslint-disable-next-line func-names
|
|---|
| 5208 | const promise = new Promise(resolve => {
|
|---|
| 5209 | token.subscribe(resolve);
|
|---|
| 5210 | _resolve = resolve;
|
|---|
| 5211 | }).then(onfulfilled);
|
|---|
| 5212 | promise.cancel = function reject() {
|
|---|
| 5213 | token.unsubscribe(_resolve);
|
|---|
| 5214 | };
|
|---|
| 5215 | return promise;
|
|---|
| 5216 | };
|
|---|
| 5217 | executor(function cancel(message, config, request) {
|
|---|
| 5218 | if (token.reason) {
|
|---|
| 5219 | // Cancellation has already been requested
|
|---|
| 5220 | return;
|
|---|
| 5221 | }
|
|---|
| 5222 | token.reason = new CanceledError(message, config, request);
|
|---|
| 5223 | resolvePromise(token.reason);
|
|---|
| 5224 | });
|
|---|
| 5225 | }
|
|---|
| 5226 |
|
|---|
| 5227 | /**
|
|---|
| 5228 | * Throws a `CanceledError` if cancellation has been requested.
|
|---|
| 5229 | */
|
|---|
| 5230 | throwIfRequested() {
|
|---|
| 5231 | if (this.reason) {
|
|---|
| 5232 | throw this.reason;
|
|---|
| 5233 | }
|
|---|
| 5234 | }
|
|---|
| 5235 |
|
|---|
| 5236 | /**
|
|---|
| 5237 | * Subscribe to the cancel signal
|
|---|
| 5238 | */
|
|---|
| 5239 |
|
|---|
| 5240 | subscribe(listener) {
|
|---|
| 5241 | if (this.reason) {
|
|---|
| 5242 | listener(this.reason);
|
|---|
| 5243 | return;
|
|---|
| 5244 | }
|
|---|
| 5245 | if (this._listeners) {
|
|---|
| 5246 | this._listeners.push(listener);
|
|---|
| 5247 | } else {
|
|---|
| 5248 | this._listeners = [listener];
|
|---|
| 5249 | }
|
|---|
| 5250 | }
|
|---|
| 5251 |
|
|---|
| 5252 | /**
|
|---|
| 5253 | * Unsubscribe from the cancel signal
|
|---|
| 5254 | */
|
|---|
| 5255 |
|
|---|
| 5256 | unsubscribe(listener) {
|
|---|
| 5257 | if (!this._listeners) {
|
|---|
| 5258 | return;
|
|---|
| 5259 | }
|
|---|
| 5260 | const index = this._listeners.indexOf(listener);
|
|---|
| 5261 | if (index !== -1) {
|
|---|
| 5262 | this._listeners.splice(index, 1);
|
|---|
| 5263 | }
|
|---|
| 5264 | }
|
|---|
| 5265 | toAbortSignal() {
|
|---|
| 5266 | const controller = new AbortController();
|
|---|
| 5267 | const abort = err => {
|
|---|
| 5268 | controller.abort(err);
|
|---|
| 5269 | };
|
|---|
| 5270 | this.subscribe(abort);
|
|---|
| 5271 | controller.signal.unsubscribe = () => this.unsubscribe(abort);
|
|---|
| 5272 | return controller.signal;
|
|---|
| 5273 | }
|
|---|
| 5274 |
|
|---|
| 5275 | /**
|
|---|
| 5276 | * Returns an object that contains a new `CancelToken` and a function that, when called,
|
|---|
| 5277 | * cancels the `CancelToken`.
|
|---|
| 5278 | */
|
|---|
| 5279 | static source() {
|
|---|
| 5280 | let cancel;
|
|---|
| 5281 | const token = new CancelToken(function executor(c) {
|
|---|
| 5282 | cancel = c;
|
|---|
| 5283 | });
|
|---|
| 5284 | return {
|
|---|
| 5285 | token,
|
|---|
| 5286 | cancel
|
|---|
| 5287 | };
|
|---|
| 5288 | }
|
|---|
| 5289 | }
|
|---|
| 5290 |
|
|---|
| 5291 | /**
|
|---|
| 5292 | * Syntactic sugar for invoking a function and expanding an array for arguments.
|
|---|
| 5293 | *
|
|---|
| 5294 | * Common use case would be to use `Function.prototype.apply`.
|
|---|
| 5295 | *
|
|---|
| 5296 | * ```js
|
|---|
| 5297 | * function f(x, y, z) {}
|
|---|
| 5298 | * const args = [1, 2, 3];
|
|---|
| 5299 | * f.apply(null, args);
|
|---|
| 5300 | * ```
|
|---|
| 5301 | *
|
|---|
| 5302 | * With `spread` this example can be re-written.
|
|---|
| 5303 | *
|
|---|
| 5304 | * ```js
|
|---|
| 5305 | * spread(function(x, y, z) {})([1, 2, 3]);
|
|---|
| 5306 | * ```
|
|---|
| 5307 | *
|
|---|
| 5308 | * @param {Function} callback
|
|---|
| 5309 | *
|
|---|
| 5310 | * @returns {Function}
|
|---|
| 5311 | */
|
|---|
| 5312 | function spread(callback) {
|
|---|
| 5313 | return function wrap(arr) {
|
|---|
| 5314 | return callback.apply(null, arr);
|
|---|
| 5315 | };
|
|---|
| 5316 | }
|
|---|
| 5317 |
|
|---|
| 5318 | /**
|
|---|
| 5319 | * Determines whether the payload is an error thrown by Axios
|
|---|
| 5320 | *
|
|---|
| 5321 | * @param {*} payload The value to test
|
|---|
| 5322 | *
|
|---|
| 5323 | * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
|---|
| 5324 | */
|
|---|
| 5325 | function isAxiosError(payload) {
|
|---|
| 5326 | return utils$1.isObject(payload) && payload.isAxiosError === true;
|
|---|
| 5327 | }
|
|---|
| 5328 |
|
|---|
| 5329 | const HttpStatusCode = {
|
|---|
| 5330 | Continue: 100,
|
|---|
| 5331 | SwitchingProtocols: 101,
|
|---|
| 5332 | Processing: 102,
|
|---|
| 5333 | EarlyHints: 103,
|
|---|
| 5334 | Ok: 200,
|
|---|
| 5335 | Created: 201,
|
|---|
| 5336 | Accepted: 202,
|
|---|
| 5337 | NonAuthoritativeInformation: 203,
|
|---|
| 5338 | NoContent: 204,
|
|---|
| 5339 | ResetContent: 205,
|
|---|
| 5340 | PartialContent: 206,
|
|---|
| 5341 | MultiStatus: 207,
|
|---|
| 5342 | AlreadyReported: 208,
|
|---|
| 5343 | ImUsed: 226,
|
|---|
| 5344 | MultipleChoices: 300,
|
|---|
| 5345 | MovedPermanently: 301,
|
|---|
| 5346 | Found: 302,
|
|---|
| 5347 | SeeOther: 303,
|
|---|
| 5348 | NotModified: 304,
|
|---|
| 5349 | UseProxy: 305,
|
|---|
| 5350 | Unused: 306,
|
|---|
| 5351 | TemporaryRedirect: 307,
|
|---|
| 5352 | PermanentRedirect: 308,
|
|---|
| 5353 | BadRequest: 400,
|
|---|
| 5354 | Unauthorized: 401,
|
|---|
| 5355 | PaymentRequired: 402,
|
|---|
| 5356 | Forbidden: 403,
|
|---|
| 5357 | NotFound: 404,
|
|---|
| 5358 | MethodNotAllowed: 405,
|
|---|
| 5359 | NotAcceptable: 406,
|
|---|
| 5360 | ProxyAuthenticationRequired: 407,
|
|---|
| 5361 | RequestTimeout: 408,
|
|---|
| 5362 | Conflict: 409,
|
|---|
| 5363 | Gone: 410,
|
|---|
| 5364 | LengthRequired: 411,
|
|---|
| 5365 | PreconditionFailed: 412,
|
|---|
| 5366 | PayloadTooLarge: 413,
|
|---|
| 5367 | UriTooLong: 414,
|
|---|
| 5368 | UnsupportedMediaType: 415,
|
|---|
| 5369 | RangeNotSatisfiable: 416,
|
|---|
| 5370 | ExpectationFailed: 417,
|
|---|
| 5371 | ImATeapot: 418,
|
|---|
| 5372 | MisdirectedRequest: 421,
|
|---|
| 5373 | UnprocessableEntity: 422,
|
|---|
| 5374 | Locked: 423,
|
|---|
| 5375 | FailedDependency: 424,
|
|---|
| 5376 | TooEarly: 425,
|
|---|
| 5377 | UpgradeRequired: 426,
|
|---|
| 5378 | PreconditionRequired: 428,
|
|---|
| 5379 | TooManyRequests: 429,
|
|---|
| 5380 | RequestHeaderFieldsTooLarge: 431,
|
|---|
| 5381 | UnavailableForLegalReasons: 451,
|
|---|
| 5382 | InternalServerError: 500,
|
|---|
| 5383 | NotImplemented: 501,
|
|---|
| 5384 | BadGateway: 502,
|
|---|
| 5385 | ServiceUnavailable: 503,
|
|---|
| 5386 | GatewayTimeout: 504,
|
|---|
| 5387 | HttpVersionNotSupported: 505,
|
|---|
| 5388 | VariantAlsoNegotiates: 506,
|
|---|
| 5389 | InsufficientStorage: 507,
|
|---|
| 5390 | LoopDetected: 508,
|
|---|
| 5391 | NotExtended: 510,
|
|---|
| 5392 | NetworkAuthenticationRequired: 511,
|
|---|
| 5393 | WebServerIsDown: 521,
|
|---|
| 5394 | ConnectionTimedOut: 522,
|
|---|
| 5395 | OriginIsUnreachable: 523,
|
|---|
| 5396 | TimeoutOccurred: 524,
|
|---|
| 5397 | SslHandshakeFailed: 525,
|
|---|
| 5398 | InvalidSslCertificate: 526
|
|---|
| 5399 | };
|
|---|
| 5400 | Object.entries(HttpStatusCode).forEach(([key, value]) => {
|
|---|
| 5401 | HttpStatusCode[value] = key;
|
|---|
| 5402 | });
|
|---|
| 5403 |
|
|---|
| 5404 | /**
|
|---|
| 5405 | * Create an instance of Axios
|
|---|
| 5406 | *
|
|---|
| 5407 | * @param {Object} defaultConfig The default config for the instance
|
|---|
| 5408 | *
|
|---|
| 5409 | * @returns {Axios} A new instance of Axios
|
|---|
| 5410 | */
|
|---|
| 5411 | function createInstance(defaultConfig) {
|
|---|
| 5412 | const context = new Axios(defaultConfig);
|
|---|
| 5413 | const instance = bind(Axios.prototype.request, context);
|
|---|
| 5414 |
|
|---|
| 5415 | // Copy axios.prototype to instance
|
|---|
| 5416 | utils$1.extend(instance, Axios.prototype, context, {
|
|---|
| 5417 | allOwnKeys: true
|
|---|
| 5418 | });
|
|---|
| 5419 |
|
|---|
| 5420 | // Copy context to instance
|
|---|
| 5421 | utils$1.extend(instance, context, null, {
|
|---|
| 5422 | allOwnKeys: true
|
|---|
| 5423 | });
|
|---|
| 5424 |
|
|---|
| 5425 | // Factory for creating new instances
|
|---|
| 5426 | instance.create = function create(instanceConfig) {
|
|---|
| 5427 | return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
|---|
| 5428 | };
|
|---|
| 5429 | return instance;
|
|---|
| 5430 | }
|
|---|
| 5431 |
|
|---|
| 5432 | // Create the default instance to be exported
|
|---|
| 5433 | const axios = createInstance(defaults);
|
|---|
| 5434 |
|
|---|
| 5435 | // Expose Axios class to allow class inheritance
|
|---|
| 5436 | axios.Axios = Axios;
|
|---|
| 5437 |
|
|---|
| 5438 | // Expose Cancel & CancelToken
|
|---|
| 5439 | axios.CanceledError = CanceledError;
|
|---|
| 5440 | axios.CancelToken = CancelToken;
|
|---|
| 5441 | axios.isCancel = isCancel;
|
|---|
| 5442 | axios.VERSION = VERSION;
|
|---|
| 5443 | axios.toFormData = toFormData;
|
|---|
| 5444 |
|
|---|
| 5445 | // Expose AxiosError class
|
|---|
| 5446 | axios.AxiosError = AxiosError;
|
|---|
| 5447 |
|
|---|
| 5448 | // alias for CanceledError for backward compatibility
|
|---|
| 5449 | axios.Cancel = axios.CanceledError;
|
|---|
| 5450 |
|
|---|
| 5451 | // Expose all/spread
|
|---|
| 5452 | axios.all = function all(promises) {
|
|---|
| 5453 | return Promise.all(promises);
|
|---|
| 5454 | };
|
|---|
| 5455 | axios.spread = spread;
|
|---|
| 5456 |
|
|---|
| 5457 | // Expose isAxiosError
|
|---|
| 5458 | axios.isAxiosError = isAxiosError;
|
|---|
| 5459 |
|
|---|
| 5460 | // Expose mergeConfig
|
|---|
| 5461 | axios.mergeConfig = mergeConfig;
|
|---|
| 5462 | axios.AxiosHeaders = AxiosHeaders;
|
|---|
| 5463 | axios.formToJSON = thing => formDataToJSON(utils$1.isHTMLForm(thing) ? new FormData(thing) : thing);
|
|---|
| 5464 | axios.getAdapter = adapters.getAdapter;
|
|---|
| 5465 | axios.HttpStatusCode = HttpStatusCode;
|
|---|
| 5466 | axios.default = axios;
|
|---|
| 5467 |
|
|---|
| 5468 | module.exports = axios;
|
|---|
| 5469 | //# sourceMappingURL=axios.cjs.map
|
|---|