mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Fixed & Imporoved AxiosHeaders class (#5224)
* Refactored AxiosHeaders class; * Added support for instances of AxiosHeaders as a value for the headers option; Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
+10
-8
@@ -47,7 +47,7 @@ class Axios {
|
||||
|
||||
config = mergeConfig(this.defaults, config);
|
||||
|
||||
const {transitional, paramsSerializer} = config;
|
||||
const {transitional, paramsSerializer, headers} = config;
|
||||
|
||||
if (transitional !== undefined) {
|
||||
validator.assertOptions(transitional, {
|
||||
@@ -67,20 +67,22 @@ class Axios {
|
||||
// Set config.method
|
||||
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
||||
|
||||
let contextHeaders;
|
||||
|
||||
// Flatten headers
|
||||
const defaultHeaders = config.headers && utils.merge(
|
||||
config.headers.common,
|
||||
config.headers[config.method]
|
||||
contextHeaders = headers && utils.merge(
|
||||
headers.common,
|
||||
headers[config.method]
|
||||
);
|
||||
|
||||
defaultHeaders && utils.forEach(
|
||||
contextHeaders && utils.forEach(
|
||||
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
||||
function cleanHeaderConfig(method) {
|
||||
delete config.headers[method];
|
||||
(method) => {
|
||||
delete headers[method];
|
||||
}
|
||||
);
|
||||
|
||||
config.headers = new AxiosHeaders(config.headers, defaultHeaders);
|
||||
config.headers = AxiosHeaders.concat(contextHeaders, headers);
|
||||
|
||||
// filter out skipped interceptors
|
||||
const requestInterceptorChain = [];
|
||||
|
||||
Reference in New Issue
Block a user