axios 0.27.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of axios might be problematic. Click here for more details.
- package/CHANGELOG.md +232 -920
- package/LICENSE +4 -16
- package/README.md +386 -103
- package/SECURITY.md +4 -3
- package/UPGRADE_GUIDE.md +1 -166
- package/bin/ssl_hotfix.js +22 -0
- package/dist/axios.js +2430 -2367
- package/dist/axios.js.map +1 -0
- package/dist/axios.min.js +2 -3
- package/dist/axios.min.js.map +1 -0
- package/dist/esm/axios.js +2950 -0
- package/dist/esm/axios.js.map +1 -0
- package/dist/esm/axios.min.js +2 -0
- package/dist/esm/axios.min.js.map +1 -0
- package/dist/node/axios.cjs +3764 -0
- package/dist/node/axios.cjs.map +1 -0
- package/gulpfile.js +88 -0
- package/index.d.ts +299 -70
- package/index.js +32 -1
- package/karma.conf.cjs +250 -0
- package/lib/adapters/http.js +378 -211
- package/lib/adapters/index.js +33 -0
- package/lib/adapters/xhr.js +81 -57
- package/lib/axios.js +34 -22
- package/lib/cancel/CancelToken.js +91 -89
- package/lib/cancel/CanceledError.js +9 -6
- package/lib/cancel/isCancel.js +2 -2
- package/lib/core/Axios.js +133 -98
- package/lib/core/AxiosError.js +22 -8
- package/lib/core/AxiosHeaders.js +268 -0
- package/lib/core/InterceptorManager.js +62 -45
- package/lib/core/buildFullPath.js +5 -4
- package/lib/core/dispatchRequest.js +21 -32
- package/lib/core/mergeConfig.js +8 -7
- package/lib/core/settle.js +6 -4
- package/lib/core/transformData.js +15 -9
- package/lib/defaults/index.js +77 -38
- package/lib/defaults/transitional.js +1 -1
- package/lib/env/classes/FormData.js +2 -0
- package/lib/env/data.js +1 -3
- package/lib/helpers/AxiosTransformStream.js +191 -0
- package/lib/helpers/AxiosURLSearchParams.js +58 -0
- package/lib/helpers/bind.js +3 -7
- package/lib/helpers/buildURL.js +26 -33
- package/lib/helpers/combineURLs.js +3 -2
- package/lib/helpers/cookies.js +43 -44
- package/lib/helpers/deprecatedMethod.js +4 -2
- package/lib/helpers/formDataToJSON.js +92 -0
- package/lib/helpers/fromDataURI.js +53 -0
- package/lib/helpers/isAbsoluteURL.js +3 -2
- package/lib/helpers/isAxiosError.js +4 -3
- package/lib/helpers/isURLSameOrigin.js +44 -45
- package/lib/helpers/null.js +1 -1
- package/lib/helpers/parseHeaders.js +24 -22
- package/lib/helpers/parseProtocol.js +3 -3
- package/lib/helpers/speedometer.js +55 -0
- package/lib/helpers/spread.js +3 -2
- package/lib/helpers/throttle.js +33 -0
- package/lib/helpers/toFormData.js +193 -36
- package/lib/helpers/toURLEncodedForm.js +18 -0
- package/lib/helpers/validator.js +20 -15
- package/lib/platform/browser/classes/FormData.js +3 -0
- package/lib/platform/browser/classes/URLSearchParams.js +4 -0
- package/lib/platform/browser/index.js +43 -0
- package/lib/platform/index.js +3 -0
- package/lib/platform/node/classes/FormData.js +3 -0
- package/lib/platform/node/classes/URLSearchParams.js +4 -0
- package/lib/platform/node/index.js +12 -0
- package/lib/utils.js +321 -178
- package/package.json +70 -23
- package/rollup.config.js +90 -0
- package/dist/axios.map +0 -1
- package/dist/axios.min.map +0 -1
- package/lib/defaults/env/FormData.js +0 -2
- package/lib/helpers/normalizeHeaderName.js +0 -12
package/lib/core/Axios.js
CHANGED
@@ -1,136 +1,171 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
import utils from './../utils.js';
|
4
|
+
import buildURL from '../helpers/buildURL.js';
|
5
|
+
import InterceptorManager from './InterceptorManager.js';
|
6
|
+
import dispatchRequest from './dispatchRequest.js';
|
7
|
+
import mergeConfig from './mergeConfig.js';
|
8
|
+
import buildFullPath from './buildFullPath.js';
|
9
|
+
import validator from '../helpers/validator.js';
|
10
|
+
import AxiosHeaders from './AxiosHeaders.js';
|
11
|
+
|
12
|
+
const validators = validator.validators;
|
13
|
+
|
12
14
|
/**
|
13
15
|
* Create a new instance of Axios
|
14
16
|
*
|
15
17
|
* @param {Object} instanceConfig The default config for the instance
|
16
|
-
*/
|
17
|
-
function Axios(instanceConfig) {
|
18
|
-
this.defaults = instanceConfig;
|
19
|
-
this.interceptors = {
|
20
|
-
request: new InterceptorManager(),
|
21
|
-
response: new InterceptorManager()
|
22
|
-
};
|
23
|
-
}
|
24
|
-
|
25
|
-
/**
|
26
|
-
* Dispatch a request
|
27
18
|
*
|
28
|
-
* @
|
19
|
+
* @return {Axios} A new instance of Axios
|
29
20
|
*/
|
30
|
-
Axios
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
config = configOrUrl || {};
|
21
|
+
class Axios {
|
22
|
+
constructor(instanceConfig) {
|
23
|
+
this.defaults = instanceConfig;
|
24
|
+
this.interceptors = {
|
25
|
+
request: new InterceptorManager(),
|
26
|
+
response: new InterceptorManager()
|
27
|
+
};
|
38
28
|
}
|
39
29
|
|
40
|
-
|
30
|
+
/**
|
31
|
+
* Dispatch a request
|
32
|
+
*
|
33
|
+
* @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
|
34
|
+
* @param {?Object} config
|
35
|
+
*
|
36
|
+
* @returns {Promise} The Promise to be fulfilled
|
37
|
+
*/
|
38
|
+
request(configOrUrl, config) {
|
39
|
+
/*eslint no-param-reassign:0*/
|
40
|
+
// Allow for axios('example/url'[, config]) a la fetch API
|
41
|
+
if (typeof configOrUrl === 'string') {
|
42
|
+
config = config || {};
|
43
|
+
config.url = configOrUrl;
|
44
|
+
} else {
|
45
|
+
config = configOrUrl || {};
|
46
|
+
}
|
41
47
|
|
42
|
-
|
43
|
-
if (config.method) {
|
44
|
-
config.method = config.method.toLowerCase();
|
45
|
-
} else if (this.defaults.method) {
|
46
|
-
config.method = this.defaults.method.toLowerCase();
|
47
|
-
} else {
|
48
|
-
config.method = 'get';
|
49
|
-
}
|
48
|
+
config = mergeConfig(this.defaults, config);
|
50
49
|
|
51
|
-
|
50
|
+
const {transitional, paramsSerializer} = config;
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
if (transitional !== undefined) {
|
53
|
+
validator.assertOptions(transitional, {
|
54
|
+
silentJSONParsing: validators.transitional(validators.boolean),
|
55
|
+
forcedJSONParsing: validators.transitional(validators.boolean),
|
56
|
+
clarifyTimeoutError: validators.transitional(validators.boolean)
|
57
|
+
}, false);
|
58
|
+
}
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
return;
|
60
|
+
if (paramsSerializer !== undefined) {
|
61
|
+
validator.assertOptions(paramsSerializer, {
|
62
|
+
encode: validators.function,
|
63
|
+
serialize: validators.function
|
64
|
+
}, true);
|
67
65
|
}
|
68
66
|
|
69
|
-
|
67
|
+
// Set config.method
|
68
|
+
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
69
|
+
|
70
|
+
// Flatten headers
|
71
|
+
const defaultHeaders = config.headers && utils.merge(
|
72
|
+
config.headers.common,
|
73
|
+
config.headers[config.method]
|
74
|
+
);
|
75
|
+
|
76
|
+
defaultHeaders && utils.forEach(
|
77
|
+
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
78
|
+
function cleanHeaderConfig(method) {
|
79
|
+
delete config.headers[method];
|
80
|
+
}
|
81
|
+
);
|
82
|
+
|
83
|
+
config.headers = new AxiosHeaders(config.headers, defaultHeaders);
|
84
|
+
|
85
|
+
// filter out skipped interceptors
|
86
|
+
const requestInterceptorChain = [];
|
87
|
+
let synchronousRequestInterceptors = true;
|
88
|
+
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
89
|
+
if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
|
90
|
+
return;
|
91
|
+
}
|
70
92
|
|
71
|
-
|
72
|
-
});
|
93
|
+
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
73
94
|
|
74
|
-
|
75
|
-
|
76
|
-
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
77
|
-
});
|
95
|
+
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
96
|
+
});
|
78
97
|
|
79
|
-
|
98
|
+
const responseInterceptorChain = [];
|
99
|
+
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
100
|
+
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
101
|
+
});
|
80
102
|
|
81
|
-
|
82
|
-
|
103
|
+
let promise;
|
104
|
+
let i = 0;
|
105
|
+
let len;
|
83
106
|
|
84
|
-
|
85
|
-
|
107
|
+
if (!synchronousRequestInterceptors) {
|
108
|
+
const chain = [dispatchRequest.bind(this), undefined];
|
109
|
+
chain.unshift.apply(chain, requestInterceptorChain);
|
110
|
+
chain.push.apply(chain, responseInterceptorChain);
|
111
|
+
len = chain.length;
|
86
112
|
|
87
|
-
|
88
|
-
|
89
|
-
|
113
|
+
promise = Promise.resolve(config);
|
114
|
+
|
115
|
+
while (i < len) {
|
116
|
+
promise = promise.then(chain[i++], chain[i++]);
|
117
|
+
}
|
118
|
+
|
119
|
+
return promise;
|
90
120
|
}
|
91
121
|
|
92
|
-
|
93
|
-
}
|
122
|
+
len = requestInterceptorChain.length;
|
94
123
|
|
124
|
+
let newConfig = config;
|
125
|
+
|
126
|
+
i = 0;
|
127
|
+
|
128
|
+
while (i < len) {
|
129
|
+
const onFulfilled = requestInterceptorChain[i++];
|
130
|
+
const onRejected = requestInterceptorChain[i++];
|
131
|
+
try {
|
132
|
+
newConfig = onFulfilled(newConfig);
|
133
|
+
} catch (error) {
|
134
|
+
onRejected.call(this, error);
|
135
|
+
break;
|
136
|
+
}
|
137
|
+
}
|
95
138
|
|
96
|
-
var newConfig = config;
|
97
|
-
while (requestInterceptorChain.length) {
|
98
|
-
var onFulfilled = requestInterceptorChain.shift();
|
99
|
-
var onRejected = requestInterceptorChain.shift();
|
100
139
|
try {
|
101
|
-
|
140
|
+
promise = dispatchRequest.call(this, newConfig);
|
102
141
|
} catch (error) {
|
103
|
-
|
104
|
-
break;
|
142
|
+
return Promise.reject(error);
|
105
143
|
}
|
106
|
-
}
|
107
144
|
|
108
|
-
|
109
|
-
|
110
|
-
} catch (error) {
|
111
|
-
return Promise.reject(error);
|
112
|
-
}
|
145
|
+
i = 0;
|
146
|
+
len = responseInterceptorChain.length;
|
113
147
|
|
114
|
-
|
115
|
-
|
116
|
-
|
148
|
+
while (i < len) {
|
149
|
+
promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
150
|
+
}
|
117
151
|
|
118
|
-
|
119
|
-
}
|
152
|
+
return promise;
|
153
|
+
}
|
120
154
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
}
|
155
|
+
getUri(config) {
|
156
|
+
config = mergeConfig(this.defaults, config);
|
157
|
+
const fullPath = buildFullPath(config.baseURL, config.url);
|
158
|
+
return buildURL(fullPath, config.params, config.paramsSerializer);
|
159
|
+
}
|
160
|
+
}
|
126
161
|
|
127
162
|
// Provide aliases for supported request methods
|
128
163
|
utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
|
129
164
|
/*eslint func-names:0*/
|
130
165
|
Axios.prototype[method] = function(url, config) {
|
131
166
|
return this.request(mergeConfig(config || {}, {
|
132
|
-
method
|
133
|
-
url
|
167
|
+
method,
|
168
|
+
url,
|
134
169
|
data: (config || {}).data
|
135
170
|
}));
|
136
171
|
};
|
@@ -142,12 +177,12 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
|
142
177
|
function generateHTTPMethod(isForm) {
|
143
178
|
return function httpMethod(url, data, config) {
|
144
179
|
return this.request(mergeConfig(config || {}, {
|
145
|
-
method
|
180
|
+
method,
|
146
181
|
headers: isForm ? {
|
147
182
|
'Content-Type': 'multipart/form-data'
|
148
183
|
} : {},
|
149
|
-
url
|
150
|
-
data
|
184
|
+
url,
|
185
|
+
data
|
151
186
|
}));
|
152
187
|
};
|
153
188
|
}
|
@@ -157,4 +192,4 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
|
157
192
|
Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
158
193
|
});
|
159
194
|
|
160
|
-
|
195
|
+
export default Axios;
|
package/lib/core/AxiosError.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
3
|
+
import utils from '../utils.js';
|
4
4
|
|
5
5
|
/**
|
6
6
|
* Create an Error with the specified message, config, error code, request and response.
|
@@ -10,10 +10,18 @@ var utils = require('../utils');
|
|
10
10
|
* @param {Object} [config] The config.
|
11
11
|
* @param {Object} [request] The request.
|
12
12
|
* @param {Object} [response] The response.
|
13
|
+
*
|
13
14
|
* @returns {Error} The created error.
|
14
15
|
*/
|
15
16
|
function AxiosError(message, code, config, request, response) {
|
16
17
|
Error.call(this);
|
18
|
+
|
19
|
+
if (Error.captureStackTrace) {
|
20
|
+
Error.captureStackTrace(this, this.constructor);
|
21
|
+
} else {
|
22
|
+
this.stack = (new Error()).stack;
|
23
|
+
}
|
24
|
+
|
17
25
|
this.message = message;
|
18
26
|
this.name = 'AxiosError';
|
19
27
|
code && (this.code = code);
|
@@ -44,8 +52,8 @@ utils.inherits(AxiosError, Error, {
|
|
44
52
|
}
|
45
53
|
});
|
46
54
|
|
47
|
-
|
48
|
-
|
55
|
+
const prototype = AxiosError.prototype;
|
56
|
+
const descriptors = {};
|
49
57
|
|
50
58
|
[
|
51
59
|
'ERR_BAD_OPTION_VALUE',
|
@@ -57,9 +65,11 @@ var descriptors = {};
|
|
57
65
|
'ERR_DEPRECATED',
|
58
66
|
'ERR_BAD_RESPONSE',
|
59
67
|
'ERR_BAD_REQUEST',
|
60
|
-
'ERR_CANCELED'
|
68
|
+
'ERR_CANCELED',
|
69
|
+
'ERR_NOT_SUPPORT',
|
70
|
+
'ERR_INVALID_URL'
|
61
71
|
// eslint-disable-next-line func-names
|
62
|
-
].forEach(
|
72
|
+
].forEach(code => {
|
63
73
|
descriptors[code] = {value: code};
|
64
74
|
});
|
65
75
|
|
@@ -67,15 +77,19 @@ Object.defineProperties(AxiosError, descriptors);
|
|
67
77
|
Object.defineProperty(prototype, 'isAxiosError', {value: true});
|
68
78
|
|
69
79
|
// eslint-disable-next-line func-names
|
70
|
-
AxiosError.from =
|
71
|
-
|
80
|
+
AxiosError.from = (error, code, config, request, response, customProps) => {
|
81
|
+
const axiosError = Object.create(prototype);
|
72
82
|
|
73
83
|
utils.toFlatObject(error, axiosError, function filter(obj) {
|
74
84
|
return obj !== Error.prototype;
|
85
|
+
}, prop => {
|
86
|
+
return prop !== 'isAxiosError';
|
75
87
|
});
|
76
88
|
|
77
89
|
AxiosError.call(axiosError, error.message, code, config, request, response);
|
78
90
|
|
91
|
+
axiosError.cause = error;
|
92
|
+
|
79
93
|
axiosError.name = error.name;
|
80
94
|
|
81
95
|
customProps && Object.assign(axiosError, customProps);
|
@@ -83,4 +97,4 @@ AxiosError.from = function(error, code, config, request, response, customProps)
|
|
83
97
|
return axiosError;
|
84
98
|
};
|
85
99
|
|
86
|
-
|
100
|
+
export default AxiosError;
|
@@ -0,0 +1,268 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
import utils from '../utils.js';
|
4
|
+
import parseHeaders from '../helpers/parseHeaders.js';
|
5
|
+
|
6
|
+
const $internals = Symbol('internals');
|
7
|
+
const $defaults = Symbol('defaults');
|
8
|
+
|
9
|
+
function normalizeHeader(header) {
|
10
|
+
return header && String(header).trim().toLowerCase();
|
11
|
+
}
|
12
|
+
|
13
|
+
function normalizeValue(value) {
|
14
|
+
if (value === false || value == null) {
|
15
|
+
return value;
|
16
|
+
}
|
17
|
+
|
18
|
+
return utils.isArray(value) ? value.map(normalizeValue) : String(value);
|
19
|
+
}
|
20
|
+
|
21
|
+
function parseTokens(str) {
|
22
|
+
const tokens = Object.create(null);
|
23
|
+
const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
|
24
|
+
let match;
|
25
|
+
|
26
|
+
while ((match = tokensRE.exec(str))) {
|
27
|
+
tokens[match[1]] = match[2];
|
28
|
+
}
|
29
|
+
|
30
|
+
return tokens;
|
31
|
+
}
|
32
|
+
|
33
|
+
function matchHeaderValue(context, value, header, filter) {
|
34
|
+
if (utils.isFunction(filter)) {
|
35
|
+
return filter.call(this, value, header);
|
36
|
+
}
|
37
|
+
|
38
|
+
if (!utils.isString(value)) return;
|
39
|
+
|
40
|
+
if (utils.isString(filter)) {
|
41
|
+
return value.indexOf(filter) !== -1;
|
42
|
+
}
|
43
|
+
|
44
|
+
if (utils.isRegExp(filter)) {
|
45
|
+
return filter.test(value);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
function formatHeader(header) {
|
50
|
+
return header.trim()
|
51
|
+
.toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
|
52
|
+
return char.toUpperCase() + str;
|
53
|
+
});
|
54
|
+
}
|
55
|
+
|
56
|
+
function buildAccessors(obj, header) {
|
57
|
+
const accessorName = utils.toCamelCase(' ' + header);
|
58
|
+
|
59
|
+
['get', 'set', 'has'].forEach(methodName => {
|
60
|
+
Object.defineProperty(obj, methodName + accessorName, {
|
61
|
+
value: function(arg1, arg2, arg3) {
|
62
|
+
return this[methodName].call(this, header, arg1, arg2, arg3);
|
63
|
+
},
|
64
|
+
configurable: true
|
65
|
+
});
|
66
|
+
});
|
67
|
+
}
|
68
|
+
|
69
|
+
function findKey(obj, key) {
|
70
|
+
key = key.toLowerCase();
|
71
|
+
const keys = Object.keys(obj);
|
72
|
+
let i = keys.length;
|
73
|
+
let _key;
|
74
|
+
while (i-- > 0) {
|
75
|
+
_key = keys[i];
|
76
|
+
if (key === _key.toLowerCase()) {
|
77
|
+
return _key;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
return null;
|
81
|
+
}
|
82
|
+
|
83
|
+
function AxiosHeaders(headers, defaults) {
|
84
|
+
headers && this.set(headers);
|
85
|
+
this[$defaults] = defaults || null;
|
86
|
+
}
|
87
|
+
|
88
|
+
Object.assign(AxiosHeaders.prototype, {
|
89
|
+
set: function(header, valueOrRewrite, rewrite) {
|
90
|
+
const self = this;
|
91
|
+
|
92
|
+
function setHeader(_value, _header, _rewrite) {
|
93
|
+
const lHeader = normalizeHeader(_header);
|
94
|
+
|
95
|
+
if (!lHeader) {
|
96
|
+
throw new Error('header name must be a non-empty string');
|
97
|
+
}
|
98
|
+
|
99
|
+
const key = findKey(self, lHeader);
|
100
|
+
|
101
|
+
if (key && _rewrite !== true && (self[key] === false || _rewrite === false)) {
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
|
105
|
+
self[key || _header] = normalizeValue(_value);
|
106
|
+
}
|
107
|
+
|
108
|
+
if (utils.isPlainObject(header)) {
|
109
|
+
utils.forEach(header, (_value, _header) => {
|
110
|
+
setHeader(_value, _header, valueOrRewrite);
|
111
|
+
});
|
112
|
+
} else {
|
113
|
+
setHeader(valueOrRewrite, header, rewrite);
|
114
|
+
}
|
115
|
+
|
116
|
+
return this;
|
117
|
+
},
|
118
|
+
|
119
|
+
get: function(header, parser) {
|
120
|
+
header = normalizeHeader(header);
|
121
|
+
|
122
|
+
if (!header) return undefined;
|
123
|
+
|
124
|
+
const key = findKey(this, header);
|
125
|
+
|
126
|
+
if (key) {
|
127
|
+
const value = this[key];
|
128
|
+
|
129
|
+
if (!parser) {
|
130
|
+
return value;
|
131
|
+
}
|
132
|
+
|
133
|
+
if (parser === true) {
|
134
|
+
return parseTokens(value);
|
135
|
+
}
|
136
|
+
|
137
|
+
if (utils.isFunction(parser)) {
|
138
|
+
return parser.call(this, value, key);
|
139
|
+
}
|
140
|
+
|
141
|
+
if (utils.isRegExp(parser)) {
|
142
|
+
return parser.exec(value);
|
143
|
+
}
|
144
|
+
|
145
|
+
throw new TypeError('parser must be boolean|regexp|function');
|
146
|
+
}
|
147
|
+
},
|
148
|
+
|
149
|
+
has: function(header, matcher) {
|
150
|
+
header = normalizeHeader(header);
|
151
|
+
|
152
|
+
if (header) {
|
153
|
+
const key = findKey(this, header);
|
154
|
+
|
155
|
+
return !!(key && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
|
156
|
+
}
|
157
|
+
|
158
|
+
return false;
|
159
|
+
},
|
160
|
+
|
161
|
+
delete: function(header, matcher) {
|
162
|
+
const self = this;
|
163
|
+
let deleted = false;
|
164
|
+
|
165
|
+
function deleteHeader(_header) {
|
166
|
+
_header = normalizeHeader(_header);
|
167
|
+
|
168
|
+
if (_header) {
|
169
|
+
const key = findKey(self, _header);
|
170
|
+
|
171
|
+
if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
|
172
|
+
delete self[key];
|
173
|
+
|
174
|
+
deleted = true;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
if (utils.isArray(header)) {
|
180
|
+
header.forEach(deleteHeader);
|
181
|
+
} else {
|
182
|
+
deleteHeader(header);
|
183
|
+
}
|
184
|
+
|
185
|
+
return deleted;
|
186
|
+
},
|
187
|
+
|
188
|
+
clear: function() {
|
189
|
+
return Object.keys(this).forEach(this.delete.bind(this));
|
190
|
+
},
|
191
|
+
|
192
|
+
normalize: function(format) {
|
193
|
+
const self = this;
|
194
|
+
const headers = {};
|
195
|
+
|
196
|
+
utils.forEach(this, (value, header) => {
|
197
|
+
const key = findKey(headers, header);
|
198
|
+
|
199
|
+
if (key) {
|
200
|
+
self[key] = normalizeValue(value);
|
201
|
+
delete self[header];
|
202
|
+
return;
|
203
|
+
}
|
204
|
+
|
205
|
+
const normalized = format ? formatHeader(header) : String(header).trim();
|
206
|
+
|
207
|
+
if (normalized !== header) {
|
208
|
+
delete self[header];
|
209
|
+
}
|
210
|
+
|
211
|
+
self[normalized] = normalizeValue(value);
|
212
|
+
|
213
|
+
headers[normalized] = true;
|
214
|
+
});
|
215
|
+
|
216
|
+
return this;
|
217
|
+
},
|
218
|
+
|
219
|
+
toJSON: function(asStrings) {
|
220
|
+
const obj = Object.create(null);
|
221
|
+
|
222
|
+
utils.forEach(Object.assign({}, this[$defaults] || null, this),
|
223
|
+
(value, header) => {
|
224
|
+
if (value == null || value === false) return;
|
225
|
+
obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value;
|
226
|
+
});
|
227
|
+
|
228
|
+
return obj;
|
229
|
+
}
|
230
|
+
});
|
231
|
+
|
232
|
+
Object.assign(AxiosHeaders, {
|
233
|
+
from: function(thing) {
|
234
|
+
if (utils.isString(thing)) {
|
235
|
+
return new this(parseHeaders(thing));
|
236
|
+
}
|
237
|
+
return thing instanceof this ? thing : new this(thing);
|
238
|
+
},
|
239
|
+
|
240
|
+
accessor: function(header) {
|
241
|
+
const internals = this[$internals] = (this[$internals] = {
|
242
|
+
accessors: {}
|
243
|
+
});
|
244
|
+
|
245
|
+
const accessors = internals.accessors;
|
246
|
+
const prototype = this.prototype;
|
247
|
+
|
248
|
+
function defineAccessor(_header) {
|
249
|
+
const lHeader = normalizeHeader(_header);
|
250
|
+
|
251
|
+
if (!accessors[lHeader]) {
|
252
|
+
buildAccessors(prototype, _header);
|
253
|
+
accessors[lHeader] = true;
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
258
|
+
|
259
|
+
return this;
|
260
|
+
}
|
261
|
+
});
|
262
|
+
|
263
|
+
AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
|
264
|
+
|
265
|
+
utils.freezeMethods(AxiosHeaders.prototype);
|
266
|
+
utils.freezeMethods(AxiosHeaders);
|
267
|
+
|
268
|
+
export default AxiosHeaders;
|