axios 1.21.1 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -40
- package/dist/axios.js +155 -9
- package/dist/axios.min.js +3 -3
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +179 -7
- package/dist/esm/axios.js +179 -7
- package/dist/esm/axios.min.js +2 -2
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +405 -102
- package/index.d.cts +12 -2
- package/index.d.ts +9 -2
- package/lib/adapters/adapters.js +21 -0
- package/lib/adapters/fetch.js +72 -3
- package/lib/adapters/http.js +181 -41
- package/lib/core/Axios.js +6 -0
- package/lib/core/AxiosHeaders.js +1 -0
- package/lib/core/InterceptorManager.js +7 -2
- package/lib/core/assertValidRequestUrl.js +62 -0
- package/lib/core/dispatchRequest.js +4 -0
- package/lib/env/data.js +1 -1
- package/lib/helpers/combineURLs.js +8 -0
- package/lib/helpers/proxyFromEnv.js +158 -0
- package/lib/helpers/shouldBypassProxy.js +2 -1
- package/lib/helpers/trackStream.js +5 -0
- package/package.json +2 -3
package/dist/node/axios.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Axios v1.
|
|
1
|
+
/*! Axios v1.22.0 Copyright (c) 2026 Matt Zabriskie and contributors */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var FormData$1 = require('form-data');
|
|
@@ -42,7 +42,7 @@ const {
|
|
|
42
42
|
} = Symbol;
|
|
43
43
|
|
|
44
44
|
/* Creating a function that will check if an object has a property. */
|
|
45
|
-
const hasOwnProperty = (({
|
|
45
|
+
const hasOwnProperty$1 = (({
|
|
46
46
|
hasOwnProperty
|
|
47
47
|
}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
|
|
48
48
|
const isUnsafeObjectKey = prop => typeof prop === 'string' && (prop === '__proto__' || prop === 'constructor' || prop === 'prototype');
|
|
@@ -114,7 +114,7 @@ const hasOwnInPrototypeChain = (thing, prop) => {
|
|
|
114
114
|
if (isPrototypeBoundary(obj, prototype, obj === thing)) {
|
|
115
115
|
return false;
|
|
116
116
|
}
|
|
117
|
-
if (hasOwnProperty(obj, prop)) {
|
|
117
|
+
if (hasOwnProperty$1(obj, prop)) {
|
|
118
118
|
return true;
|
|
119
119
|
}
|
|
120
120
|
obj = prototype;
|
|
@@ -175,7 +175,7 @@ const toSafeFlatObject = thing => {
|
|
|
175
175
|
if (isUnsafeObjectKey(prop)) {
|
|
176
176
|
continue;
|
|
177
177
|
}
|
|
178
|
-
if (!hasOwnProperty(merged, prop)) {
|
|
178
|
+
if (!hasOwnProperty$1(merged, prop)) {
|
|
179
179
|
result[prop] = thing[prop];
|
|
180
180
|
merged[prop] = true;
|
|
181
181
|
}
|
|
@@ -316,7 +316,7 @@ const isPlainObject = val => {
|
|
|
316
316
|
// and stops before even those when `val` is itself the boundary
|
|
317
317
|
// Object.prototype. Checking that inline avoids allocating the walker's
|
|
318
318
|
// `seen` list twice per call on the mergeConfig / merge hot path.
|
|
319
|
-
isPrototypeBoundary(val, prototype, true) || !hasOwnProperty(val, toStringTag) && !hasOwnProperty(val, iterator));
|
|
319
|
+
isPrototypeBoundary(val, prototype, true) || !hasOwnProperty$1(val, toStringTag) && !hasOwnProperty$1(val, iterator));
|
|
320
320
|
};
|
|
321
321
|
|
|
322
322
|
/**
|
|
@@ -584,7 +584,7 @@ function merge(...objs) {
|
|
|
584
584
|
const knownKey = lowerCaseKeys[lowerKey];
|
|
585
585
|
// A key recorded but absent from `result` was skipped by skipUndefined;
|
|
586
586
|
// the later spelling wins then, as it does for findKey.
|
|
587
|
-
if (knownKey !== undefined && hasOwnProperty(result, knownKey)) {
|
|
587
|
+
if (knownKey !== undefined && hasOwnProperty$1(result, knownKey)) {
|
|
588
588
|
targetKey = knownKey;
|
|
589
589
|
} else {
|
|
590
590
|
lowerCaseKeys[lowerKey] = key;
|
|
@@ -593,7 +593,7 @@ function merge(...objs) {
|
|
|
593
593
|
// Read via own-prop only — a bare `result[targetKey]` walks the prototype
|
|
594
594
|
// chain, so a polluted Object.prototype value could surface here and get
|
|
595
595
|
// copied into the merged result.
|
|
596
|
-
const existing = hasOwnProperty(result, targetKey) ? result[targetKey] : undefined;
|
|
596
|
+
const existing = hasOwnProperty$1(result, targetKey) ? result[targetKey] : undefined;
|
|
597
597
|
if (isPlainObject(existing) && isPlainObject(val)) {
|
|
598
598
|
result[targetKey] = merge(existing, val);
|
|
599
599
|
} else if (isPlainObject(val)) {
|
|
@@ -779,7 +779,7 @@ const toArray = thing => {
|
|
|
779
779
|
if (isPrototypeBoundary(source, prototype, source === thing)) break;
|
|
780
780
|
Object.getOwnPropertyNames(source).forEach(key => {
|
|
781
781
|
const index = +key;
|
|
782
|
-
if (Number.isInteger(index) && index >= 0 && index < i && String(index) === key && hasOwnProperty(source, key)) {
|
|
782
|
+
if (Number.isInteger(index) && index >= 0 && index < i && String(index) === key && hasOwnProperty$1(source, key)) {
|
|
783
783
|
indexes.add(index);
|
|
784
784
|
}
|
|
785
785
|
});
|
|
@@ -1092,8 +1092,8 @@ var utils$1 = {
|
|
|
1092
1092
|
forEachEntry,
|
|
1093
1093
|
matchAll,
|
|
1094
1094
|
isHTMLForm,
|
|
1095
|
-
hasOwnProperty,
|
|
1096
|
-
hasOwnProp: hasOwnProperty,
|
|
1095
|
+
hasOwnProperty: hasOwnProperty$1,
|
|
1096
|
+
hasOwnProp: hasOwnProperty$1,
|
|
1097
1097
|
// an alias to avoid ESLint no-prototype-builtins detection
|
|
1098
1098
|
hasOwnInPrototypeChain,
|
|
1099
1099
|
getSafeProp,
|
|
@@ -1529,7 +1529,7 @@ class AxiosHeaders {
|
|
|
1529
1529
|
return this;
|
|
1530
1530
|
}
|
|
1531
1531
|
}
|
|
1532
|
-
AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
|
|
1532
|
+
AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Content-Encoding', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
|
|
1533
1533
|
|
|
1534
1534
|
// reserved names hotfix
|
|
1535
1535
|
utils$1.reduceDescriptors(AxiosHeaders.prototype, ({
|
|
@@ -2178,8 +2178,10 @@ class InterceptorManager {
|
|
|
2178
2178
|
const handler = {
|
|
2179
2179
|
fulfilled,
|
|
2180
2180
|
rejected,
|
|
2181
|
-
|
|
2182
|
-
|
|
2181
|
+
// Options from a class or template object are read as usual; a value
|
|
2182
|
+
// only inherited from Object.prototype is ignored.
|
|
2183
|
+
synchronous: options && utils$1.hasOwnInPrototypeChain(options, 'synchronous') ? options.synchronous : false,
|
|
2184
|
+
runWhen: options && utils$1.hasOwnInPrototypeChain(options, 'runWhen') ? options.runWhen : null
|
|
2183
2185
|
};
|
|
2184
2186
|
const internals = this[$internals];
|
|
2185
2187
|
if (this.handlers == null) {
|
|
@@ -2705,6 +2707,13 @@ function combineURLs(baseURL, relativeURL) {
|
|
|
2705
2707
|
while (end > 0 && baseURL.charCodeAt(end - 1) === 47) {
|
|
2706
2708
|
end--;
|
|
2707
2709
|
}
|
|
2710
|
+
if (end === 0) {
|
|
2711
|
+
// A base made only of slashes points at the root of the current origin.
|
|
2712
|
+
// Drop leading slashes, backslashes, tabs and newlines from the relative
|
|
2713
|
+
// URL as well: URL parsers ignore tabs and newlines and treat '\\' as '/',
|
|
2714
|
+
// so leaving them would turn the result into a protocol-relative URL.
|
|
2715
|
+
return '/' + relativeURL.replace(/^[/\\\t\n\r]+/, '');
|
|
2716
|
+
}
|
|
2708
2717
|
return baseURL.slice(0, end) + '/' + relativeURL.replace(/^\/+/, '');
|
|
2709
2718
|
}
|
|
2710
2719
|
|
|
@@ -2785,7 +2794,34 @@ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls, config) {
|
|
|
2785
2794
|
return requestedURL;
|
|
2786
2795
|
}
|
|
2787
2796
|
|
|
2788
|
-
|
|
2797
|
+
// Resolves the proxy for a URL from the standard proxy environment variables.
|
|
2798
|
+
// Adapted from proxy-from-env 2.1.0 (https://github.com/Rob--W/proxy-from-env).
|
|
2799
|
+
// A variable that is not set on process.env itself is ignored when
|
|
2800
|
+
// Object.prototype has a property of the same name. The port of a parsed URL
|
|
2801
|
+
// is also read as a decimal number.
|
|
2802
|
+
//
|
|
2803
|
+
// proxy-from-env is distributed under the MIT License:
|
|
2804
|
+
//
|
|
2805
|
+
// Copyright (C) 2016-2018 Rob Wu <rob@robwu.nl>
|
|
2806
|
+
//
|
|
2807
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
2808
|
+
// this software and associated documentation files (the "Software"), to deal in
|
|
2809
|
+
// the Software without restriction, including without limitation the rights to
|
|
2810
|
+
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
2811
|
+
// of the Software, and to permit persons to whom the Software is furnished to do
|
|
2812
|
+
// so, subject to the following conditions:
|
|
2813
|
+
//
|
|
2814
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
2815
|
+
// copies or substantial portions of the Software.
|
|
2816
|
+
//
|
|
2817
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
2818
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
2819
|
+
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
2820
|
+
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
2821
|
+
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
2822
|
+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
2823
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2824
|
+
const DEFAULT_PORTS$1 = {
|
|
2789
2825
|
ftp: 21,
|
|
2790
2826
|
gopher: 70,
|
|
2791
2827
|
http: 80,
|
|
@@ -2796,92 +2832,107 @@ var DEFAULT_PORTS$1 = {
|
|
|
2796
2832
|
function parseUrl(urlString) {
|
|
2797
2833
|
try {
|
|
2798
2834
|
return new URL(urlString);
|
|
2799
|
-
} catch {
|
|
2835
|
+
} catch (err) {
|
|
2800
2836
|
return null;
|
|
2801
2837
|
}
|
|
2802
2838
|
}
|
|
2803
2839
|
|
|
2804
2840
|
/**
|
|
2805
|
-
*
|
|
2806
|
-
*
|
|
2807
|
-
*
|
|
2808
|
-
*
|
|
2841
|
+
* Read one environment variable without trusting Object.prototype.
|
|
2842
|
+
*
|
|
2843
|
+
* A name that is not set on process.env itself is ignored when Object.prototype
|
|
2844
|
+
* has a property of the same name. Any other name is read as usual, so an env
|
|
2845
|
+
* object that a test runner replaces or wraps keeps working.
|
|
2846
|
+
*
|
|
2847
|
+
* @param {string} name The exact name of the environment variable.
|
|
2848
|
+
* @returns {string|undefined} The value, or undefined when it must not be used.
|
|
2809
2849
|
*/
|
|
2810
|
-
function
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
var port = parsedUrl.port;
|
|
2815
|
-
if (typeof hostname !== 'string' || !hostname || typeof proto !== 'string') {
|
|
2816
|
-
return ''; // Don't proxy URLs without a valid scheme or host.
|
|
2817
|
-
}
|
|
2818
|
-
proto = proto.split(':', 1)[0];
|
|
2819
|
-
// Stripping ports in this way instead of using parsedUrl.hostname to make
|
|
2820
|
-
// sure that the brackets around IPv6 addresses are kept.
|
|
2821
|
-
hostname = hostname.replace(/:\d*$/, '');
|
|
2822
|
-
port = parseInt(port) || DEFAULT_PORTS$1[proto] || 0;
|
|
2823
|
-
if (!shouldProxy(hostname, port)) {
|
|
2824
|
-
return ''; // Don't proxy URLs that match NO_PROXY.
|
|
2825
|
-
}
|
|
2826
|
-
var proxy = getEnv(proto + '_proxy') || getEnv('all_proxy');
|
|
2827
|
-
if (proxy && proxy.indexOf('://') === -1) {
|
|
2828
|
-
// Missing scheme in proxy, default to the requested URL's scheme.
|
|
2829
|
-
proxy = proto + '://' + proxy;
|
|
2850
|
+
function readEnv(name) {
|
|
2851
|
+
const env = process.env;
|
|
2852
|
+
if (name in Object.prototype && !hasOwnProperty.call(env, name)) {
|
|
2853
|
+
return undefined;
|
|
2830
2854
|
}
|
|
2831
|
-
return
|
|
2855
|
+
return env[name];
|
|
2856
|
+
}
|
|
2857
|
+
|
|
2858
|
+
/**
|
|
2859
|
+
* Get the value of an environment variable, preferring the lower-case name.
|
|
2860
|
+
*
|
|
2861
|
+
* @param {string} key The name of the environment variable.
|
|
2862
|
+
* @returns {string} The value, or an empty string when it is not set.
|
|
2863
|
+
*/
|
|
2864
|
+
function getEnv(key) {
|
|
2865
|
+
return readEnv(key.toLowerCase()) || readEnv(key.toUpperCase()) || '';
|
|
2832
2866
|
}
|
|
2833
2867
|
|
|
2834
2868
|
/**
|
|
2835
|
-
*
|
|
2869
|
+
* Determine whether a request to the given host and port should be proxied,
|
|
2870
|
+
* according to no_proxy.
|
|
2836
2871
|
*
|
|
2837
|
-
* @param {string} hostname
|
|
2838
|
-
* @param {number} port
|
|
2839
|
-
* @returns {boolean} Whether the
|
|
2840
|
-
* @private
|
|
2872
|
+
* @param {string} hostname The host of the URL, with IPv6 brackets kept.
|
|
2873
|
+
* @param {number} port The effective port of the URL.
|
|
2874
|
+
* @returns {boolean} Whether the request should be proxied.
|
|
2841
2875
|
*/
|
|
2842
2876
|
function shouldProxy(hostname, port) {
|
|
2843
|
-
|
|
2844
|
-
if (!
|
|
2845
|
-
return true;
|
|
2877
|
+
const noProxy = getEnv('no_proxy').toLowerCase();
|
|
2878
|
+
if (!noProxy) {
|
|
2879
|
+
return true;
|
|
2846
2880
|
}
|
|
2847
|
-
if (
|
|
2848
|
-
return false;
|
|
2881
|
+
if (noProxy === '*') {
|
|
2882
|
+
return false;
|
|
2849
2883
|
}
|
|
2850
|
-
return
|
|
2851
|
-
if (!
|
|
2852
|
-
return true;
|
|
2884
|
+
return noProxy.split(/[,\s]/).every(entry => {
|
|
2885
|
+
if (!entry) {
|
|
2886
|
+
return true;
|
|
2853
2887
|
}
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
if (
|
|
2858
|
-
return true;
|
|
2888
|
+
const parsedEntry = entry.match(/^(.+):(\d+)$/);
|
|
2889
|
+
let entryHostname = parsedEntry ? parsedEntry[1] : entry;
|
|
2890
|
+
const entryPort = parsedEntry ? parseInt(parsedEntry[2], 10) : 0;
|
|
2891
|
+
if (entryPort && entryPort !== port) {
|
|
2892
|
+
return true;
|
|
2859
2893
|
}
|
|
2860
|
-
if (!/^[.*]/.test(
|
|
2861
|
-
|
|
2862
|
-
return hostname !== parsedProxyHostname;
|
|
2894
|
+
if (!/^[.*]/.test(entryHostname)) {
|
|
2895
|
+
return hostname !== entryHostname;
|
|
2863
2896
|
}
|
|
2864
|
-
if (
|
|
2865
|
-
|
|
2866
|
-
parsedProxyHostname = parsedProxyHostname.slice(1);
|
|
2897
|
+
if (entryHostname.charAt(0) === '*') {
|
|
2898
|
+
entryHostname = entryHostname.slice(1);
|
|
2867
2899
|
}
|
|
2868
|
-
|
|
2869
|
-
return !hostname.endsWith(parsedProxyHostname);
|
|
2900
|
+
return !hostname.endsWith(entryHostname);
|
|
2870
2901
|
});
|
|
2871
2902
|
}
|
|
2872
2903
|
|
|
2873
2904
|
/**
|
|
2874
|
-
* Get the
|
|
2905
|
+
* Get the proxy URL that should handle a request to the given URL.
|
|
2875
2906
|
*
|
|
2876
|
-
* @param {string}
|
|
2877
|
-
*
|
|
2878
|
-
* @
|
|
2907
|
+
* @param {string|URL|Object} url The request URL, a URL instance, or a
|
|
2908
|
+
* compatible object such as the result of url.parse.
|
|
2909
|
+
* @returns {string} The proxy URL, or an empty string when no proxy applies.
|
|
2879
2910
|
*/
|
|
2880
|
-
function
|
|
2881
|
-
|
|
2911
|
+
function getProxyForUrl(url) {
|
|
2912
|
+
const parsedUrl = (typeof url === 'string' ? parseUrl(url) : url) || {};
|
|
2913
|
+
let proto = parsedUrl.protocol;
|
|
2914
|
+
let hostname = parsedUrl.host;
|
|
2915
|
+
let port = parsedUrl.port;
|
|
2916
|
+
if (typeof hostname !== 'string' || !hostname || typeof proto !== 'string') {
|
|
2917
|
+
return '';
|
|
2918
|
+
}
|
|
2919
|
+
proto = proto.split(':', 1)[0];
|
|
2920
|
+
// Strip the port this way rather than using parsedUrl.hostname so the
|
|
2921
|
+
// brackets around IPv6 addresses are kept.
|
|
2922
|
+
hostname = hostname.replace(/:\d*$/, '');
|
|
2923
|
+
port = parseInt(port, 10) || DEFAULT_PORTS$1[proto] || 0;
|
|
2924
|
+
if (!shouldProxy(hostname, port)) {
|
|
2925
|
+
return '';
|
|
2926
|
+
}
|
|
2927
|
+
let proxy = getEnv(proto + '_proxy') || getEnv('all_proxy');
|
|
2928
|
+
if (proxy && proxy.indexOf('://') === -1) {
|
|
2929
|
+
// No scheme in the proxy value: default to the request URL's scheme.
|
|
2930
|
+
proxy = proto + '://' + proxy;
|
|
2931
|
+
}
|
|
2932
|
+
return proxy;
|
|
2882
2933
|
}
|
|
2883
2934
|
|
|
2884
|
-
const VERSION = "1.
|
|
2935
|
+
const VERSION = "1.22.0";
|
|
2885
2936
|
|
|
2886
2937
|
function parseProtocol(url) {
|
|
2887
2938
|
const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url);
|
|
@@ -3677,7 +3728,7 @@ function shouldBypassProxy(location) {
|
|
|
3677
3728
|
} catch (_err) {
|
|
3678
3729
|
return false;
|
|
3679
3730
|
}
|
|
3680
|
-
const noProxy = (
|
|
3731
|
+
const noProxy = getEnv('no_proxy').toLowerCase();
|
|
3681
3732
|
if (!noProxy) {
|
|
3682
3733
|
return false;
|
|
3683
3734
|
}
|
|
@@ -4123,6 +4174,41 @@ function getDirectAgent(configuredAgent, transport) {
|
|
|
4123
4174
|
}
|
|
4124
4175
|
return direct;
|
|
4125
4176
|
}
|
|
4177
|
+
|
|
4178
|
+
// Windows named pipes and Linux abstract sockets (leading NUL byte) are not
|
|
4179
|
+
// filesystem paths, so they are compared and connected to as given.
|
|
4180
|
+
function isNonFileSocketPath(socketPath) {
|
|
4181
|
+
return /^\\\\[.?]\\pipe\\/i.test(socketPath) || socketPath.charAt(0) === '\0';
|
|
4182
|
+
}
|
|
4183
|
+
function normalizeSocketPath(socketPath) {
|
|
4184
|
+
return isNonFileSocketPath(socketPath) ? socketPath : path.resolve(socketPath);
|
|
4185
|
+
}
|
|
4186
|
+
|
|
4187
|
+
// The longest socket path every supported platform accepts: sun_path is 104
|
|
4188
|
+
// bytes on macOS and the BSDs and 108 on Linux, including the trailing NUL.
|
|
4189
|
+
const MAX_SOCKET_PATH_BYTES = 103;
|
|
4190
|
+
|
|
4191
|
+
// The path to connect to when an allowlist is in use. `..` is collapsed
|
|
4192
|
+
// lexically, as the allowlist check does, so the path that is connected is the
|
|
4193
|
+
// path that was checked.
|
|
4194
|
+
//
|
|
4195
|
+
// The absolute path is used whenever it fits, so the target does not depend on
|
|
4196
|
+
// the working directory when the connection opens (an Agent can open it later,
|
|
4197
|
+
// after a process.chdir()). Only when the absolute path is too long is the
|
|
4198
|
+
// shorter path relative to the working directory used. Either way the result
|
|
4199
|
+
// is never longer than the absolute path, because some Node versions silently
|
|
4200
|
+
// truncate a socket path that is too long and would connect to a prefix of it.
|
|
4201
|
+
function getConnectSocketPath(socketPath) {
|
|
4202
|
+
if (isNonFileSocketPath(socketPath)) {
|
|
4203
|
+
return socketPath;
|
|
4204
|
+
}
|
|
4205
|
+
const resolved = path.resolve(socketPath);
|
|
4206
|
+
if (path.isAbsolute(socketPath) || Buffer.byteLength(resolved) <= MAX_SOCKET_PATH_BYTES) {
|
|
4207
|
+
return resolved;
|
|
4208
|
+
}
|
|
4209
|
+
const relative = path.relative(process.cwd(), resolved) || '.';
|
|
4210
|
+
return Buffer.byteLength(relative) < Buffer.byteLength(resolved) ? relative : resolved;
|
|
4211
|
+
}
|
|
4126
4212
|
function setDirectAgent(options, configHttpAgent, configHttpsAgent) {
|
|
4127
4213
|
const secure = isHttps.test(options.protocol);
|
|
4128
4214
|
const agent = getDirectAgent(secure ? configHttpsAgent : configHttpAgent, secure ? https : http);
|
|
@@ -4185,6 +4271,41 @@ const flushOnFinish = (stream, [throttled, flush]) => {
|
|
|
4185
4271
|
};
|
|
4186
4272
|
const http2Sessions = new Http2Sessions();
|
|
4187
4273
|
|
|
4274
|
+
// Options that follow-redirects reads but axios does not always set.
|
|
4275
|
+
// follow-redirects copies the request options into a plain object, so any of
|
|
4276
|
+
// these left unset would be read from Object.prototype. hostname and port are
|
|
4277
|
+
// only unset for socketPath requests, and sensitiveHeaders only with a custom
|
|
4278
|
+
// transport. Checked against follow-redirects 1.16.3; a later release that
|
|
4279
|
+
// reads more options needs them added here.
|
|
4280
|
+
const REDIRECT_OPTION_KEYS = ['host', 'hostname', 'port', 'pathname', 'search', 'hash', 'query', 'slashes', 'followRedirects', 'trackRedirects', 'sensitiveHeaders'];
|
|
4281
|
+
|
|
4282
|
+
// follow-redirects reads these when a response arrives rather than when the
|
|
4283
|
+
// request starts, so they are pinned even when nothing is inherited yet.
|
|
4284
|
+
const RESPONSE_OPTION_KEYS = new Set(['followRedirects', 'trackRedirects']);
|
|
4285
|
+
|
|
4286
|
+
/**
|
|
4287
|
+
* Give the options follow-redirects reads an own value whenever one would
|
|
4288
|
+
* otherwise be inherited. dispatchBeforeRedirect also resets host, auth and
|
|
4289
|
+
* query on each redirect hop. Other keys that are not inherited are left
|
|
4290
|
+
* unset, so the options passed to the transport do not change otherwise.
|
|
4291
|
+
*
|
|
4292
|
+
* The check is against Object.prototype rather than `key in options`: the
|
|
4293
|
+
* initial options object has a null prototype, and follow-redirects copies it
|
|
4294
|
+
* into a plain object that inherits from Object.prototype.
|
|
4295
|
+
*
|
|
4296
|
+
* @param {Object<string, any>} options
|
|
4297
|
+
*/
|
|
4298
|
+
function setRedirectDefaults(options) {
|
|
4299
|
+
REDIRECT_OPTION_KEYS.forEach(key => {
|
|
4300
|
+
if (utils$1.hasOwnProp(options, key)) {
|
|
4301
|
+
return;
|
|
4302
|
+
}
|
|
4303
|
+
if (key in Object.prototype || RESPONSE_OPTION_KEYS.has(key)) {
|
|
4304
|
+
options[key] = undefined;
|
|
4305
|
+
}
|
|
4306
|
+
});
|
|
4307
|
+
}
|
|
4308
|
+
|
|
4188
4309
|
/**
|
|
4189
4310
|
* If the proxy, auth, sensitive header, or config beforeRedirects functions are defined,
|
|
4190
4311
|
* call them with the options object.
|
|
@@ -4194,9 +4315,13 @@ const http2Sessions = new Http2Sessions();
|
|
|
4194
4315
|
* @returns {Object<string, any>}
|
|
4195
4316
|
*/
|
|
4196
4317
|
function dispatchBeforeRedirect(options, responseDetails, requestDetails) {
|
|
4318
|
+
// follow-redirects copies auth and query from a WHATWG URL, which has
|
|
4319
|
+
// neither, so both would otherwise be read from Object.prototype. Own Basic
|
|
4320
|
+
// credentials are restored on same-origin hops by beforeRedirects.auth.
|
|
4321
|
+
options.auth = undefined;
|
|
4322
|
+
options.query = undefined;
|
|
4197
4323
|
if (!isSameOriginRedirect(options, requestDetails)) {
|
|
4198
4324
|
stripMatchingHeaders(options.headers, new Set(['authorization', 'cookie']));
|
|
4199
|
-
delete options.auth;
|
|
4200
4325
|
}
|
|
4201
4326
|
if (options.beforeRedirects.proxy) {
|
|
4202
4327
|
options.beforeRedirects.proxy(options);
|
|
@@ -4213,6 +4338,14 @@ function dispatchBeforeRedirect(options, responseDetails, requestDetails) {
|
|
|
4213
4338
|
if (options.beforeRedirects.config) {
|
|
4214
4339
|
options.beforeRedirects.config(options, responseDetails, requestDetails);
|
|
4215
4340
|
}
|
|
4341
|
+
// follow-redirects deletes a truthy host after this hook returns, which
|
|
4342
|
+
// would let the next hop read host from Object.prototype. Fold it into
|
|
4343
|
+
// hostname the same way follow-redirects does, but keep an own value.
|
|
4344
|
+
if (options.host && !options.hostname) {
|
|
4345
|
+
options.hostname = options.host;
|
|
4346
|
+
}
|
|
4347
|
+
options.host = undefined;
|
|
4348
|
+
setRedirectDefaults(options);
|
|
4216
4349
|
}
|
|
4217
4350
|
function stripMatchingHeaders(headers, sensitiveSet) {
|
|
4218
4351
|
if (!headers) {
|
|
@@ -4555,8 +4688,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
4555
4688
|
connectPhaseTimer = null;
|
|
4556
4689
|
}
|
|
4557
4690
|
}
|
|
4558
|
-
function createTimeoutError() {
|
|
4559
|
-
const configTimeout = own('timeout');
|
|
4691
|
+
function createTimeoutError(configTimeout = own('timeout')) {
|
|
4560
4692
|
let timeoutErrorMessage = configTimeout ? 'timeout of ' + configTimeout + 'ms exceeded' : 'timeout exceeded';
|
|
4561
4693
|
const configTimeoutErrorMessage = own('timeoutErrorMessage');
|
|
4562
4694
|
if (configTimeoutErrorMessage) {
|
|
@@ -4721,17 +4853,6 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
4721
4853
|
} else {
|
|
4722
4854
|
maxUploadRate = maxDownloadRate = maxRate;
|
|
4723
4855
|
}
|
|
4724
|
-
if (data && (onUploadProgress || maxUploadRate)) {
|
|
4725
|
-
if (!utils$1.isStream(data)) {
|
|
4726
|
-
data = stream.Readable.from(data, {
|
|
4727
|
-
objectMode: false
|
|
4728
|
-
});
|
|
4729
|
-
}
|
|
4730
|
-
data = stream.pipeline([data, new AxiosTransformStream({
|
|
4731
|
-
maxRate: utils$1.toFiniteNumber(maxUploadRate)
|
|
4732
|
-
})], utils$1.noop);
|
|
4733
|
-
onUploadProgress && data.on('progress', flushOnFinish(data, progressEventDecorator(contentLength, progressEventReducer(asyncDecorator(onUploadProgress, scheduleProgress), false, 3))));
|
|
4734
|
-
}
|
|
4735
4856
|
|
|
4736
4857
|
// HTTP basic authentication
|
|
4737
4858
|
let auth = undefined;
|
|
@@ -4747,9 +4868,9 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
4747
4868
|
auth = urlUsername + ':' + urlPassword;
|
|
4748
4869
|
}
|
|
4749
4870
|
auth && headers.delete('authorization');
|
|
4750
|
-
let path
|
|
4871
|
+
let path;
|
|
4751
4872
|
try {
|
|
4752
|
-
path
|
|
4873
|
+
path = buildURL(parsed.pathname + parsed.search, own('params'), own('paramsSerializer')).replace(/^\?/, '');
|
|
4753
4874
|
} catch (err) {
|
|
4754
4875
|
return reject(AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config, null, null, {
|
|
4755
4876
|
url: own('url'),
|
|
@@ -4766,7 +4887,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
4766
4887
|
// Null-prototype to block prototype pollution gadgets on properties read
|
|
4767
4888
|
// directly by Node's http.request (e.g. insecureHTTPParser, lookup).
|
|
4768
4889
|
const options = Object.assign(Object.create(null), {
|
|
4769
|
-
path
|
|
4890
|
+
path,
|
|
4770
4891
|
method: method,
|
|
4771
4892
|
headers: toByteStringHeaderObject(headers),
|
|
4772
4893
|
agents: {
|
|
@@ -4789,17 +4910,28 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
4789
4910
|
if (typeof socketPath !== 'string') {
|
|
4790
4911
|
return reject(new AxiosError('socketPath must be a string', AxiosError.ERR_BAD_OPTION_VALUE, config));
|
|
4791
4912
|
}
|
|
4913
|
+
let connectSocketPath = socketPath;
|
|
4792
4914
|
const allowedSocketPaths = own('allowedSocketPaths');
|
|
4793
4915
|
if (allowedSocketPaths != null) {
|
|
4794
4916
|
const allowed = Array.isArray(allowedSocketPaths) ? allowedSocketPaths : [allowedSocketPaths];
|
|
4795
|
-
|
|
4796
|
-
|
|
4917
|
+
|
|
4918
|
+
// Check the path that will be connected, so the two cannot disagree.
|
|
4919
|
+
connectSocketPath = getConnectSocketPath(socketPath);
|
|
4920
|
+
const normalizedSocket = normalizeSocketPath(connectSocketPath);
|
|
4921
|
+
const isAllowed = allowed.some(entry => typeof entry === 'string' && normalizeSocketPath(entry) === normalizedSocket);
|
|
4797
4922
|
if (!isAllowed) {
|
|
4798
4923
|
return reject(new AxiosError(`socketPath "${socketPath}" is not permitted by allowedSocketPaths`, AxiosError.ERR_BAD_OPTION_VALUE, config));
|
|
4799
4924
|
}
|
|
4800
4925
|
}
|
|
4801
|
-
options.socketPath =
|
|
4926
|
+
options.socketPath = connectSocketPath;
|
|
4802
4927
|
} else {
|
|
4928
|
+
// Node 14 and older copy the request options into a plain object in
|
|
4929
|
+
// Agent#addRequest and read socketPath from that copy, so an inherited
|
|
4930
|
+
// value would turn this into a socket request. Only set when one is
|
|
4931
|
+
// inherited, so the options passed on do not change otherwise.
|
|
4932
|
+
if ('socketPath' in Object.prototype) {
|
|
4933
|
+
options.socketPath = undefined;
|
|
4934
|
+
}
|
|
4803
4935
|
options.hostname = parsed.hostname.startsWith('[') ? parsed.hostname.slice(1, -1) : parsed.hostname;
|
|
4804
4936
|
options.port = parsed.port;
|
|
4805
4937
|
proxyApplied = setProxy(options, configProxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path, false, httpsAgent, httpAgent,
|
|
@@ -4829,6 +4961,8 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
4829
4961
|
} else {
|
|
4830
4962
|
const configTransport = own('transport');
|
|
4831
4963
|
if (configTransport) {
|
|
4964
|
+
// A custom transport may be follow-redirects itself.
|
|
4965
|
+
setRedirectDefaults(options);
|
|
4832
4966
|
transport = configTransport;
|
|
4833
4967
|
} else if (maxRedirects === 0) {
|
|
4834
4968
|
transport = isHttpsRequest ? https : http;
|
|
@@ -4880,6 +5014,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
4880
5014
|
};
|
|
4881
5015
|
}
|
|
4882
5016
|
}
|
|
5017
|
+
setRedirectDefaults(options);
|
|
4883
5018
|
transport = isHttpsRequest ? httpsFollow : httpFollow;
|
|
4884
5019
|
}
|
|
4885
5020
|
}
|
|
@@ -4898,6 +5033,39 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
4898
5033
|
// through Node's internal options copy
|
|
4899
5034
|
options.insecureHTTPParser = Boolean(own('insecureHTTPParser'));
|
|
4900
5035
|
|
|
5036
|
+
// Read and convert the timeout once, so the value checked here is the value applied and
|
|
5037
|
+
// reported below, and fail a negative timeout (for example from a deadline that has
|
|
5038
|
+
// already passed) as an elapsed timeout before connecting. Passed through, Node would
|
|
5039
|
+
// throw a RangeError that follow-redirects raises outside this promise. It runs after the
|
|
5040
|
+
// other config checks so their errors win, and data: URLs above never apply a timeout.
|
|
5041
|
+
// parseFloat also treats fractions such as -0.5 as elapsed (parseInt yields -0, which
|
|
5042
|
+
// disables the timeout on the native transport), and parseInt catches strings such as
|
|
5043
|
+
// '-1e-324' that parseFloat reads as -0.
|
|
5044
|
+
const rawTimeout = own('timeout');
|
|
5045
|
+
let timeoutString;
|
|
5046
|
+
let parsedTimeout;
|
|
5047
|
+
if (rawTimeout) {
|
|
5048
|
+
timeoutString = `${rawTimeout}`;
|
|
5049
|
+
parsedTimeout = parseInt(timeoutString, 10);
|
|
5050
|
+
if (parseFloat(timeoutString) < 0 || parsedTimeout < 0) {
|
|
5051
|
+
return reject(createTimeoutError(timeoutString));
|
|
5052
|
+
}
|
|
5053
|
+
}
|
|
5054
|
+
|
|
5055
|
+
// Start the upload pipeline only once the request goes ahead, so a config rejected above
|
|
5056
|
+
// never starts reading the body.
|
|
5057
|
+
if (data && (onUploadProgress || maxUploadRate)) {
|
|
5058
|
+
if (!utils$1.isStream(data)) {
|
|
5059
|
+
data = stream.Readable.from(data, {
|
|
5060
|
+
objectMode: false
|
|
5061
|
+
});
|
|
5062
|
+
}
|
|
5063
|
+
data = stream.pipeline([data, new AxiosTransformStream({
|
|
5064
|
+
maxRate: utils$1.toFiniteNumber(maxUploadRate)
|
|
5065
|
+
})], utils$1.noop);
|
|
5066
|
+
onUploadProgress && data.on('progress', flushOnFinish(data, progressEventDecorator(contentLength, progressEventReducer(asyncDecorator(onUploadProgress, scheduleProgress), false, 3))));
|
|
5067
|
+
}
|
|
5068
|
+
|
|
4901
5069
|
// Create the request
|
|
4902
5070
|
req = transport.request(options, function handleResponse(res) {
|
|
4903
5071
|
clearConnectPhaseTimer();
|
|
@@ -5091,16 +5259,18 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
5091
5259
|
});
|
|
5092
5260
|
|
|
5093
5261
|
// Handle request timeout
|
|
5094
|
-
if (
|
|
5095
|
-
//
|
|
5096
|
-
|
|
5097
|
-
|
|
5262
|
+
if (rawTimeout) {
|
|
5263
|
+
// An int timeout, converted once above, avoids problems if the `req` interface doesn't
|
|
5264
|
+
// handle other types. Node also rejects non-finite values, such as the Infinity that
|
|
5265
|
+
// parseInt returns for a very long digit string, so treat those as unparsable too.
|
|
5266
|
+
const timeout = parsedTimeout;
|
|
5267
|
+
if (!Number.isFinite(timeout)) {
|
|
5098
5268
|
abort(new AxiosError('error trying to parse `config.timeout` to int', AxiosError.ERR_BAD_OPTION_VALUE, config, req));
|
|
5099
5269
|
return;
|
|
5100
5270
|
}
|
|
5101
5271
|
const handleTimeout = function handleTimeout() {
|
|
5102
5272
|
if (isDone) return;
|
|
5103
|
-
abort(createTimeoutError());
|
|
5273
|
+
abort(createTimeoutError(timeoutString));
|
|
5104
5274
|
};
|
|
5105
5275
|
if (isNativeTransport && timeout > 0) {
|
|
5106
5276
|
// Native ClientRequest#setTimeout starts from the socket lifecycle and
|
|
@@ -6010,6 +6180,11 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
|
|
6010
6180
|
}
|
|
6011
6181
|
controller.enqueue(new Uint8Array(value));
|
|
6012
6182
|
} catch (err) {
|
|
6183
|
+
// A progress callback can fail while the source iterator is suspended at
|
|
6184
|
+
// a yield. Close it without delaying or replacing the original error.
|
|
6185
|
+
// This return() call has no cancellation reason, so the source's cancel()
|
|
6186
|
+
// receives undefined, as it does from the cancel() hook below.
|
|
6187
|
+
iterator.return().catch(() => {});
|
|
6013
6188
|
_onFinish(err);
|
|
6014
6189
|
throw err;
|
|
6015
6190
|
}
|
|
@@ -6185,6 +6360,42 @@ const test = (fn, ...args) => {
|
|
|
6185
6360
|
return false;
|
|
6186
6361
|
}
|
|
6187
6362
|
};
|
|
6363
|
+
|
|
6364
|
+
// Marks a probe body's cancellation result as handled. Reads `then` once and
|
|
6365
|
+
// does not go through the global Promise or `Promise.prototype.catch`, so a
|
|
6366
|
+
// rejected cancellation from a custom body cannot surface as an unhandled
|
|
6367
|
+
// rejection.
|
|
6368
|
+
const ignoreRejection = result => {
|
|
6369
|
+
try {
|
|
6370
|
+
if (result !== null && (typeof result === 'object' || typeof result === 'function')) {
|
|
6371
|
+
const then = result.then;
|
|
6372
|
+
if (isFunction(then)) {
|
|
6373
|
+
then.call(result, undefined, utils$1.noop);
|
|
6374
|
+
}
|
|
6375
|
+
}
|
|
6376
|
+
} catch (e) {
|
|
6377
|
+
// Ignored: the cancellation has already been requested.
|
|
6378
|
+
}
|
|
6379
|
+
};
|
|
6380
|
+
|
|
6381
|
+
// On Node.js 22 and older, the body of the throwaway `new Response('')` used by
|
|
6382
|
+
// the response-stream probe leaves its stream's internal closed promise pending
|
|
6383
|
+
// until the stream is cancelled, which async-leak detectors report for every
|
|
6384
|
+
// realm that loads axios. This cleanup runs in `finally`, whether the check
|
|
6385
|
+
// returned or threw, and is best-effort so it never affects the probe result.
|
|
6386
|
+
const cancelProbeBody = body => {
|
|
6387
|
+
if (body == null) {
|
|
6388
|
+
return;
|
|
6389
|
+
}
|
|
6390
|
+
try {
|
|
6391
|
+
const cancel = body.cancel;
|
|
6392
|
+
if (isFunction(cancel)) {
|
|
6393
|
+
ignoreRejection(cancel.call(body));
|
|
6394
|
+
}
|
|
6395
|
+
} catch (e) {
|
|
6396
|
+
// Ignored: an uncancellable probe body is still a valid probe result.
|
|
6397
|
+
}
|
|
6398
|
+
};
|
|
6188
6399
|
const maybeWithAuthCredentials = url => {
|
|
6189
6400
|
const protocolIndex = url.indexOf('://');
|
|
6190
6401
|
let urlToCheck = url;
|
|
@@ -6232,11 +6443,18 @@ const factory = env => {
|
|
|
6232
6443
|
});
|
|
6233
6444
|
const hasContentType = request.headers.has('Content-Type');
|
|
6234
6445
|
if (request.body != null) {
|
|
6235
|
-
request.body.cancel();
|
|
6446
|
+
ignoreRejection(request.body.cancel());
|
|
6236
6447
|
}
|
|
6237
6448
|
return duplexAccessed && !hasContentType;
|
|
6238
6449
|
});
|
|
6239
|
-
const supportsResponseStream = isResponseSupported && isReadableStreamSupported && test(() =>
|
|
6450
|
+
const supportsResponseStream = isResponseSupported && isReadableStreamSupported && test(() => {
|
|
6451
|
+
const probeBody = new Response('').body;
|
|
6452
|
+
try {
|
|
6453
|
+
return utils$1.isReadableStream(probeBody);
|
|
6454
|
+
} finally {
|
|
6455
|
+
cancelProbeBody(probeBody);
|
|
6456
|
+
}
|
|
6457
|
+
});
|
|
6240
6458
|
|
|
6241
6459
|
// Some runtimes reject every explicit cache mode. Use own defaults for both
|
|
6242
6460
|
// probes so unrelated polluted options cannot affect cache-mode detection.
|
|
@@ -6613,6 +6831,25 @@ const factory = env => {
|
|
|
6613
6831
|
};
|
|
6614
6832
|
};
|
|
6615
6833
|
const seedCache = new Map();
|
|
6834
|
+
|
|
6835
|
+
// Every adapter the factory has created. The adapter is cached per
|
|
6836
|
+
// environment, so one created for another environment, such as by
|
|
6837
|
+
// `axios.getAdapter('fetch')` without a config, is still recognized.
|
|
6838
|
+
const createdAdapters = new WeakSet();
|
|
6839
|
+
const createAdapter = env => {
|
|
6840
|
+
const adapter = factory(env);
|
|
6841
|
+
adapter && createdAdapters.add(adapter);
|
|
6842
|
+
return adapter;
|
|
6843
|
+
};
|
|
6844
|
+
|
|
6845
|
+
/**
|
|
6846
|
+
* Check whether a function was created by the fetch adapter factory.
|
|
6847
|
+
*
|
|
6848
|
+
* @param {*} adapter The value to check
|
|
6849
|
+
*
|
|
6850
|
+
* @returns {boolean} `true` for a built-in fetch adapter
|
|
6851
|
+
*/
|
|
6852
|
+
const isFetchAdapter = adapter => createdAdapters.has(adapter);
|
|
6616
6853
|
const getFetch = config => {
|
|
6617
6854
|
const env = Object.create(null);
|
|
6618
6855
|
const configuredEnv = config && utils$1.hasOwnProp(config, 'env') && config.env;
|
|
@@ -6636,7 +6873,7 @@ const getFetch = config => {
|
|
|
6636
6873
|
while (i--) {
|
|
6637
6874
|
seed = seeds[i];
|
|
6638
6875
|
target = map.get(seed);
|
|
6639
|
-
target === undefined && map.set(seed, target = i ? new Map() :
|
|
6876
|
+
target === undefined && map.set(seed, target = i ? new Map() : createAdapter(env));
|
|
6640
6877
|
map = target;
|
|
6641
6878
|
}
|
|
6642
6879
|
return target;
|
|
@@ -6737,6 +6974,16 @@ function getAdapter(adapters, config) {
|
|
|
6737
6974
|
return adapter;
|
|
6738
6975
|
}
|
|
6739
6976
|
|
|
6977
|
+
/**
|
|
6978
|
+
* Check whether a resolved adapter function is one of the built-in adapters.
|
|
6979
|
+
*
|
|
6980
|
+
* @param {Function} adapter The adapter resolved by `getAdapter`
|
|
6981
|
+
* @returns {boolean} `true` for the built-in `xhr`, `http` or `fetch` adapter
|
|
6982
|
+
*/
|
|
6983
|
+
function isBuiltinAdapter(adapter) {
|
|
6984
|
+
return !!adapter && (adapter === knownAdapters.xhr || adapter === knownAdapters.http || isFetchAdapter(adapter));
|
|
6985
|
+
}
|
|
6986
|
+
|
|
6740
6987
|
/**
|
|
6741
6988
|
* Exports Axios adapters and utility to resolve an adapter
|
|
6742
6989
|
*/
|
|
@@ -6746,6 +6993,11 @@ var adapters = {
|
|
|
6746
6993
|
* @type {Function}
|
|
6747
6994
|
*/
|
|
6748
6995
|
getAdapter,
|
|
6996
|
+
/**
|
|
6997
|
+
* Check whether a resolved adapter is a built-in one.
|
|
6998
|
+
* @type {Function}
|
|
6999
|
+
*/
|
|
7000
|
+
isBuiltinAdapter,
|
|
6749
7001
|
/**
|
|
6750
7002
|
* Exposes all known adapters
|
|
6751
7003
|
* @type {Object<string, Function|Object>}
|
|
@@ -6753,6 +7005,53 @@ var adapters = {
|
|
|
6753
7005
|
adapters: knownAdapters
|
|
6754
7006
|
};
|
|
6755
7007
|
|
|
7008
|
+
/**
|
|
7009
|
+
* Reject a `null` or `undefined` url that a built-in adapter would send
|
|
7010
|
+
* somewhere the caller did not choose.
|
|
7011
|
+
*
|
|
7012
|
+
* With params, the nullish url becomes a query-only url such as `?foo=bar`,
|
|
7013
|
+
* which a browser resolves against the current page. Without params, XHR
|
|
7014
|
+
* requests `./null` or `./undefined` and the Node adapter throws a native
|
|
7015
|
+
* `TypeError`.
|
|
7016
|
+
*
|
|
7017
|
+
* The request still has a destination when `baseURL` is set, or when the Node
|
|
7018
|
+
* HTTP adapter is given a `socketPath`. A caller-supplied adapter handles its
|
|
7019
|
+
* own destination and is not checked.
|
|
7020
|
+
*
|
|
7021
|
+
* `dispatchRequest` and `Axios#getUri` both call this, so `getUri` rejects
|
|
7022
|
+
* exactly the configs that a request would reject. Request interceptors are
|
|
7023
|
+
* not run by `getUri`, so a url that an interceptor would supply is still
|
|
7024
|
+
* missing there. Keep this out of `buildURL` and `buildFullPath`: they only
|
|
7025
|
+
* format urls and have other callers.
|
|
7026
|
+
*
|
|
7027
|
+
* @param {Object} config The merged request config
|
|
7028
|
+
* @param {Function} resolveAdapter Returns the adapter that handles the
|
|
7029
|
+
* request. Called only for a nullish url without `baseURL`, so a usable url
|
|
7030
|
+
* never depends on adapter resolution.
|
|
7031
|
+
*
|
|
7032
|
+
* @returns {void}
|
|
7033
|
+
*/
|
|
7034
|
+
function assertValidRequestUrl(config, resolveAdapter) {
|
|
7035
|
+
const url = utils$1.getSafeProp(config, 'url');
|
|
7036
|
+
if (url !== null && url !== undefined) {
|
|
7037
|
+
return;
|
|
7038
|
+
}
|
|
7039
|
+
if (utils$1.getSafeProp(config, 'baseURL')) {
|
|
7040
|
+
return;
|
|
7041
|
+
}
|
|
7042
|
+
const adapter = resolveAdapter();
|
|
7043
|
+
|
|
7044
|
+
// Only the Node HTTP adapter reads socketPath; XHR and fetch ignore it.
|
|
7045
|
+
const httpAdapter = adapters.adapters.http;
|
|
7046
|
+
if (httpAdapter && adapter === httpAdapter && utils$1.getSafeProp(config, 'socketPath')) {
|
|
7047
|
+
return;
|
|
7048
|
+
}
|
|
7049
|
+
if (!adapters.isBuiltinAdapter(adapter)) {
|
|
7050
|
+
return;
|
|
7051
|
+
}
|
|
7052
|
+
throw new AxiosError(`Invalid URL: url cannot be ${url === null ? 'null' : 'undefined'} when baseURL is not set`, AxiosError.ERR_INVALID_URL, config);
|
|
7053
|
+
}
|
|
7054
|
+
|
|
6756
7055
|
/**
|
|
6757
7056
|
* Throws a `CanceledError` if cancellation has been requested.
|
|
6758
7057
|
*
|
|
@@ -6819,6 +7118,9 @@ function dispatchRequest(_config) {
|
|
|
6819
7118
|
config.headers.setContentType('application/x-www-form-urlencoded', false);
|
|
6820
7119
|
}
|
|
6821
7120
|
const adapter = adapters.getAdapter(config.adapter || defaults.adapter, config);
|
|
7121
|
+
|
|
7122
|
+
// Runs after resolution so a custom adapter is recognized in any form.
|
|
7123
|
+
assertValidRequestUrl(config, () => adapter);
|
|
6822
7124
|
const now = resolveClock();
|
|
6823
7125
|
const start = now();
|
|
6824
7126
|
return adapter(config).then(function onAdapterResolution(response) {
|
|
@@ -7162,6 +7464,7 @@ class Axios {
|
|
|
7162
7464
|
}
|
|
7163
7465
|
getUri(config) {
|
|
7164
7466
|
config = mergeConfig(this.defaults, config);
|
|
7467
|
+
assertValidRequestUrl(config, () => adapters.getAdapter(config.adapter || defaults.adapter, config));
|
|
7165
7468
|
const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls, config);
|
|
7166
7469
|
return buildURL(fullPath, config.params, config.paramsSerializer);
|
|
7167
7470
|
}
|