axios 0.27.2 → 1.0.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.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

Files changed (75) hide show
  1. package/CHANGELOG.md +178 -940
  2. package/LICENSE +4 -16
  3. package/README.md +292 -93
  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 +2537 -2211
  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 +2942 -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 +3750 -0
  16. package/dist/node/axios.cjs.map +1 -0
  17. package/gulpfile.js +88 -0
  18. package/index.d.ts +293 -70
  19. package/index.js +2 -1
  20. package/karma.conf.cjs +250 -0
  21. package/lib/adapters/http.js +371 -212
  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 +127 -99
  29. package/lib/core/AxiosError.js +22 -8
  30. package/lib/core/AxiosHeaders.js +274 -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 +24 -38
  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 +320 -177
  70. package/package.json +69 -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,164 @@
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);
41
-
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
- }
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
+ }
50
47
 
51
- var transitional = config.transitional;
48
+ config = mergeConfig(this.defaults, config);
52
49
 
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
- }
50
+ const transitional = config.transitional;
60
51
 
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;
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);
67
58
  }
68
59
 
69
- synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
60
+ // Set config.method
61
+ config.method = (config.method || this.defaults.method || 'get').toLowerCase();
62
+
63
+ // Flatten headers
64
+ const defaultHeaders = config.headers && utils.merge(
65
+ config.headers.common,
66
+ config.headers[config.method]
67
+ );
68
+
69
+ defaultHeaders && utils.forEach(
70
+ ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
71
+ function cleanHeaderConfig(method) {
72
+ delete config.headers[method];
73
+ }
74
+ );
75
+
76
+ config.headers = new AxiosHeaders(config.headers, defaultHeaders);
77
+
78
+ // filter out skipped interceptors
79
+ const requestInterceptorChain = [];
80
+ let synchronousRequestInterceptors = true;
81
+ this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
82
+ if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
83
+ return;
84
+ }
70
85
 
71
- requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
72
- });
86
+ synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
73
87
 
74
- var responseInterceptorChain = [];
75
- this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
76
- responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
77
- });
88
+ requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
89
+ });
78
90
 
79
- var promise;
91
+ const responseInterceptorChain = [];
92
+ this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
93
+ responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
94
+ });
80
95
 
81
- if (!synchronousRequestInterceptors) {
82
- var chain = [dispatchRequest, undefined];
96
+ let promise;
97
+ let i = 0;
98
+ let len;
83
99
 
84
- Array.prototype.unshift.apply(chain, requestInterceptorChain);
85
- chain = chain.concat(responseInterceptorChain);
100
+ if (!synchronousRequestInterceptors) {
101
+ const chain = [dispatchRequest.bind(this), undefined];
102
+ chain.unshift.apply(chain, requestInterceptorChain);
103
+ chain.push.apply(chain, responseInterceptorChain);
104
+ len = chain.length;
86
105
 
87
- promise = Promise.resolve(config);
88
- while (chain.length) {
89
- promise = promise.then(chain.shift(), chain.shift());
106
+ promise = Promise.resolve(config);
107
+
108
+ while (i < len) {
109
+ promise = promise.then(chain[i++], chain[i++]);
110
+ }
111
+
112
+ return promise;
90
113
  }
91
114
 
92
- return promise;
93
- }
115
+ len = requestInterceptorChain.length;
94
116
 
117
+ let newConfig = config;
118
+
119
+ i = 0;
120
+
121
+ while (i < len) {
122
+ const onFulfilled = requestInterceptorChain[i++];
123
+ const onRejected = requestInterceptorChain[i++];
124
+ try {
125
+ newConfig = onFulfilled(newConfig);
126
+ } catch (error) {
127
+ onRejected.call(this, error);
128
+ break;
129
+ }
130
+ }
95
131
 
96
- var newConfig = config;
97
- while (requestInterceptorChain.length) {
98
- var onFulfilled = requestInterceptorChain.shift();
99
- var onRejected = requestInterceptorChain.shift();
100
132
  try {
101
- newConfig = onFulfilled(newConfig);
133
+ promise = dispatchRequest.call(this, newConfig);
102
134
  } catch (error) {
103
- onRejected(error);
104
- break;
135
+ return Promise.reject(error);
105
136
  }
106
- }
107
137
 
108
- try {
109
- promise = dispatchRequest(newConfig);
110
- } catch (error) {
111
- return Promise.reject(error);
112
- }
138
+ i = 0;
139
+ len = responseInterceptorChain.length;
113
140
 
114
- while (responseInterceptorChain.length) {
115
- promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
116
- }
141
+ while (i < len) {
142
+ promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
143
+ }
117
144
 
118
- return promise;
119
- };
145
+ return promise;
146
+ }
120
147
 
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
- };
148
+ getUri(config) {
149
+ config = mergeConfig(this.defaults, config);
150
+ const fullPath = buildFullPath(config.baseURL, config.url);
151
+ return buildURL(fullPath, config.params, config.paramsSerializer);
152
+ }
153
+ }
126
154
 
127
155
  // Provide aliases for supported request methods
128
156
  utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
129
157
  /*eslint func-names:0*/
130
158
  Axios.prototype[method] = function(url, config) {
131
159
  return this.request(mergeConfig(config || {}, {
132
- method: method,
133
- url: url,
160
+ method,
161
+ url,
134
162
  data: (config || {}).data
135
163
  }));
136
164
  };
@@ -142,12 +170,12 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
142
170
  function generateHTTPMethod(isForm) {
143
171
  return function httpMethod(url, data, config) {
144
172
  return this.request(mergeConfig(config || {}, {
145
- method: method,
173
+ method,
146
174
  headers: isForm ? {
147
175
  'Content-Type': 'multipart/form-data'
148
176
  } : {},
149
- url: url,
150
- data: data
177
+ url,
178
+ data
151
179
  }));
152
180
  };
153
181
  }
@@ -157,4 +185,4 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
157
185
  Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
158
186
  });
159
187
 
160
- module.exports = Axios;
188
+ 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,274 @@
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 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
+ if (utils.isArray(_value)) {
106
+ _value = _value.map(normalizeValue);
107
+ } else {
108
+ _value = normalizeValue(_value);
109
+ }
110
+
111
+ self[key || _header] = _value;
112
+ }
113
+
114
+ if (utils.isPlainObject(header)) {
115
+ utils.forEach(header, (_value, _header) => {
116
+ setHeader(_value, _header, valueOrRewrite);
117
+ });
118
+ } else {
119
+ setHeader(valueOrRewrite, header, rewrite);
120
+ }
121
+
122
+ return this;
123
+ },
124
+
125
+ get: function(header, parser) {
126
+ header = normalizeHeader(header);
127
+
128
+ if (!header) return undefined;
129
+
130
+ const key = findKey(this, header);
131
+
132
+ if (key) {
133
+ const value = this[key];
134
+
135
+ if (!parser) {
136
+ return value;
137
+ }
138
+
139
+ if (parser === true) {
140
+ return parseTokens(value);
141
+ }
142
+
143
+ if (utils.isFunction(parser)) {
144
+ return parser.call(this, value, key);
145
+ }
146
+
147
+ if (utils.isRegExp(parser)) {
148
+ return parser.exec(value);
149
+ }
150
+
151
+ throw new TypeError('parser must be boolean|regexp|function');
152
+ }
153
+ },
154
+
155
+ has: function(header, matcher) {
156
+ header = normalizeHeader(header);
157
+
158
+ if (header) {
159
+ const key = findKey(this, header);
160
+
161
+ return !!(key && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
162
+ }
163
+
164
+ return false;
165
+ },
166
+
167
+ delete: function(header, matcher) {
168
+ const self = this;
169
+ let deleted = false;
170
+
171
+ function deleteHeader(_header) {
172
+ _header = normalizeHeader(_header);
173
+
174
+ if (_header) {
175
+ const key = findKey(self, _header);
176
+
177
+ if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
178
+ delete self[key];
179
+
180
+ deleted = true;
181
+ }
182
+ }
183
+ }
184
+
185
+ if (utils.isArray(header)) {
186
+ header.forEach(deleteHeader);
187
+ } else {
188
+ deleteHeader(header);
189
+ }
190
+
191
+ return deleted;
192
+ },
193
+
194
+ clear: function() {
195
+ return Object.keys(this).forEach(this.delete.bind(this));
196
+ },
197
+
198
+ normalize: function(format) {
199
+ const self = this;
200
+ const headers = {};
201
+
202
+ utils.forEach(this, (value, header) => {
203
+ const key = findKey(headers, header);
204
+
205
+ if (key) {
206
+ self[key] = normalizeValue(value);
207
+ delete self[header];
208
+ return;
209
+ }
210
+
211
+ const normalized = format ? formatHeader(header) : String(header).trim();
212
+
213
+ if (normalized !== header) {
214
+ delete self[header];
215
+ }
216
+
217
+ self[normalized] = normalizeValue(value);
218
+
219
+ headers[normalized] = true;
220
+ });
221
+
222
+ return this;
223
+ },
224
+
225
+ toJSON: function() {
226
+ const obj = Object.create(null);
227
+
228
+ utils.forEach(Object.assign({}, this[$defaults] || null, this),
229
+ (value, header) => {
230
+ if (value == null || value === false) return;
231
+ obj[header] = utils.isArray(value) ? value.join(', ') : value;
232
+ });
233
+
234
+ return obj;
235
+ }
236
+ });
237
+
238
+ Object.assign(AxiosHeaders, {
239
+ from: function(thing) {
240
+ if (utils.isString(thing)) {
241
+ return new this(parseHeaders(thing));
242
+ }
243
+ return thing instanceof this ? thing : new this(thing);
244
+ },
245
+
246
+ accessor: function(header) {
247
+ const internals = this[$internals] = (this[$internals] = {
248
+ accessors: {}
249
+ });
250
+
251
+ const accessors = internals.accessors;
252
+ const prototype = this.prototype;
253
+
254
+ function defineAccessor(_header) {
255
+ const lHeader = normalizeHeader(_header);
256
+
257
+ if (!accessors[lHeader]) {
258
+ buildAccessors(prototype, _header);
259
+ accessors[lHeader] = true;
260
+ }
261
+ }
262
+
263
+ utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
264
+
265
+ return this;
266
+ }
267
+ });
268
+
269
+ AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
270
+
271
+ utils.freezeMethods(AxiosHeaders.prototype);
272
+ utils.freezeMethods(AxiosHeaders);
273
+
274
+ export default AxiosHeaders;