2023-03-28 21:32:54 +08:00
|
|
|
import { isPlainObject } from '../helpers/isTypes';
|
2023-04-02 18:26:24 +08:00
|
|
|
import { ignore } from '../helpers/ignore';
|
2023-03-28 20:48:02 +08:00
|
|
|
import { AxiosRequestConfig, AxiosRequestHeaders } from './Axios';
|
2023-03-23 20:09:00 +08:00
|
|
|
|
|
|
|
export function flattenHeaders(
|
|
|
|
config: AxiosRequestConfig,
|
|
|
|
): AxiosRequestHeaders | undefined {
|
|
|
|
if (!isPlainObject(config.headers)) {
|
|
|
|
return config.headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...(config.headers.common ?? {}),
|
2023-03-28 20:48:02 +08:00
|
|
|
...(config.headers[config.method!.toLowerCase()] ?? {}),
|
2023-04-02 18:26:24 +08:00
|
|
|
...ignore(
|
2023-03-23 20:09:00 +08:00
|
|
|
config.headers,
|
|
|
|
'common',
|
|
|
|
'options',
|
|
|
|
'get',
|
|
|
|
'head',
|
|
|
|
'post',
|
|
|
|
'put',
|
|
|
|
'delete',
|
|
|
|
'trace',
|
|
|
|
'connect',
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|