2
0
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:
Dmitriy Mozgovoy
2022-11-07 21:11:42 +02:00
committed by GitHub
parent c0a723ab6c
commit ab77a40e1c
16 changed files with 321 additions and 159 deletions
+10 -8
View File
@@ -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 = [];