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.

Files changed (75) hide show
  1. package/CHANGELOG.md +232 -920
  2. package/LICENSE +4 -16
  3. package/README.md +386 -103
  4. package/SECURITY.md +4 -3
  5. package/UPGRADE_GUIDE.md +1 -166
  6. package/bin/ssl_hotfix.js +22 -0
  7. package/dist/axios.js +2430 -2367
  8. package/dist/axios.js.map +1 -0
  9. package/dist/axios.min.js +2 -3
  10. package/dist/axios.min.js.map +1 -0
  11. package/dist/esm/axios.js +2950 -0
  12. package/dist/esm/axios.js.map +1 -0
  13. package/dist/esm/axios.min.js +2 -0
  14. package/dist/esm/axios.min.js.map +1 -0
  15. package/dist/node/axios.cjs +3764 -0
  16. package/dist/node/axios.cjs.map +1 -0
  17. package/gulpfile.js +88 -0
  18. package/index.d.ts +299 -70
  19. package/index.js +32 -1
  20. package/karma.conf.cjs +250 -0
  21. package/lib/adapters/http.js +378 -211
  22. package/lib/adapters/index.js +33 -0
  23. package/lib/adapters/xhr.js +81 -57
  24. package/lib/axios.js +34 -22
  25. package/lib/cancel/CancelToken.js +91 -89
  26. package/lib/cancel/CanceledError.js +9 -6
  27. package/lib/cancel/isCancel.js +2 -2
  28. package/lib/core/Axios.js +133 -98
  29. package/lib/core/AxiosError.js +22 -8
  30. package/lib/core/AxiosHeaders.js +268 -0
  31. package/lib/core/InterceptorManager.js +62 -45
  32. package/lib/core/buildFullPath.js +5 -4
  33. package/lib/core/dispatchRequest.js +21 -32
  34. package/lib/core/mergeConfig.js +8 -7
  35. package/lib/core/settle.js +6 -4
  36. package/lib/core/transformData.js +15 -9
  37. package/lib/defaults/index.js +77 -38
  38. package/lib/defaults/transitional.js +1 -1
  39. package/lib/env/classes/FormData.js +2 -0
  40. package/lib/env/data.js +1 -3
  41. package/lib/helpers/AxiosTransformStream.js +191 -0
  42. package/lib/helpers/AxiosURLSearchParams.js +58 -0
  43. package/lib/helpers/bind.js +3 -7
  44. package/lib/helpers/buildURL.js +26 -33
  45. package/lib/helpers/combineURLs.js +3 -2
  46. package/lib/helpers/cookies.js +43 -44
  47. package/lib/helpers/deprecatedMethod.js +4 -2
  48. package/lib/helpers/formDataToJSON.js +92 -0
  49. package/lib/helpers/fromDataURI.js +53 -0
  50. package/lib/helpers/isAbsoluteURL.js +3 -2
  51. package/lib/helpers/isAxiosError.js +4 -3
  52. package/lib/helpers/isURLSameOrigin.js +44 -45
  53. package/lib/helpers/null.js +1 -1
  54. package/lib/helpers/parseHeaders.js +24 -22
  55. package/lib/helpers/parseProtocol.js +3 -3
  56. package/lib/helpers/speedometer.js +55 -0
  57. package/lib/helpers/spread.js +3 -2
  58. package/lib/helpers/throttle.js +33 -0
  59. package/lib/helpers/toFormData.js +193 -36
  60. package/lib/helpers/toURLEncodedForm.js +18 -0
  61. package/lib/helpers/validator.js +20 -15
  62. package/lib/platform/browser/classes/FormData.js +3 -0
  63. package/lib/platform/browser/classes/URLSearchParams.js +4 -0
  64. package/lib/platform/browser/index.js +43 -0
  65. package/lib/platform/index.js +3 -0
  66. package/lib/platform/node/classes/FormData.js +3 -0
  67. package/lib/platform/node/classes/URLSearchParams.js +4 -0
  68. package/lib/platform/node/index.js +12 -0
  69. package/lib/utils.js +321 -178
  70. package/package.json +70 -23
  71. package/rollup.config.js +90 -0
  72. package/dist/axios.map +0 -1
  73. package/dist/axios.min.map +0 -1
  74. package/lib/defaults/env/FormData.js +0 -2
  75. package/lib/helpers/normalizeHeaderName.js +0 -12
package/lib/core/Axios.js CHANGED
@@ -1,136 +1,171 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('./../utils');
4
- var buildURL = require('../helpers/buildURL');
5
- var InterceptorManager = require('./InterceptorManager');
6
- var dispatchRequest = require('./dispatchRequest');
7
- var mergeConfig = require('./mergeConfig');
8
- var buildFullPath = require('./buildFullPath');
9
- var validator = require('../helpers/validator');
10
-
11
- var validators = validator.validators;
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
- * @param {Object} config The config specific for this request (merged with this.defaults)
19
+ * @return {Axios} A new instance of Axios
29
20
  */
30
- Axios.prototype.request = function request(configOrUrl, config) {
31
- /*eslint no-param-reassign:0*/
32
- // Allow for axios('example/url'[, config]) a la fetch API
33
- if (typeof configOrUrl === 'string') {
34
- config = config || {};
35
- config.url = configOrUrl;
36
- } else {
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
- config = mergeConfig(this.defaults, config);
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
- // Set config.method
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
- var transitional = config.transitional;
50
+ const {transitional, paramsSerializer} = config;
52
51
 
53
- if (transitional !== undefined) {
54
- validator.assertOptions(transitional, {
55
- silentJSONParsing: validators.transitional(validators.boolean),
56
- forcedJSONParsing: validators.transitional(validators.boolean),
57
- clarifyTimeoutError: validators.transitional(validators.boolean)
58
- }, false);
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
- // filter out skipped interceptors
62
- var requestInterceptorChain = [];
63
- var synchronousRequestInterceptors = true;
64
- this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
65
- if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
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
- synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
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
- requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
72
- });
93
+ synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
73
94
 
74
- var responseInterceptorChain = [];
75
- this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
76
- responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
77
- });
95
+ requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
96
+ });
78
97
 
79
- var promise;
98
+ const responseInterceptorChain = [];
99
+ this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
100
+ responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
101
+ });
80
102
 
81
- if (!synchronousRequestInterceptors) {
82
- var chain = [dispatchRequest, undefined];
103
+ let promise;
104
+ let i = 0;
105
+ let len;
83
106
 
84
- Array.prototype.unshift.apply(chain, requestInterceptorChain);
85
- chain = chain.concat(responseInterceptorChain);
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
- promise = Promise.resolve(config);
88
- while (chain.length) {
89
- promise = promise.then(chain.shift(), chain.shift());
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
- return promise;
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
- newConfig = onFulfilled(newConfig);
140
+ promise = dispatchRequest.call(this, newConfig);
102
141
  } catch (error) {
103
- onRejected(error);
104
- break;
142
+ return Promise.reject(error);
105
143
  }
106
- }
107
144
 
108
- try {
109
- promise = dispatchRequest(newConfig);
110
- } catch (error) {
111
- return Promise.reject(error);
112
- }
145
+ i = 0;
146
+ len = responseInterceptorChain.length;
113
147
 
114
- while (responseInterceptorChain.length) {
115
- promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
116
- }
148
+ while (i < len) {
149
+ promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
150
+ }
117
151
 
118
- return promise;
119
- };
152
+ return promise;
153
+ }
120
154
 
121
- Axios.prototype.getUri = function getUri(config) {
122
- config = mergeConfig(this.defaults, config);
123
- var fullPath = buildFullPath(config.baseURL, config.url);
124
- return buildURL(fullPath, config.params, config.paramsSerializer);
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: method,
133
- url: 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: method,
180
+ method,
146
181
  headers: isForm ? {
147
182
  'Content-Type': 'multipart/form-data'
148
183
  } : {},
149
- url: url,
150
- data: 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
- module.exports = Axios;
195
+ export default Axios;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('../utils');
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
- var prototype = AxiosError.prototype;
48
- var descriptors = {};
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(function(code) {
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 = function(error, code, config, request, response, customProps) {
71
- var axiosError = Object.create(prototype);
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
- module.exports = AxiosError;
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;