mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-12-29 17:36:57 +08:00
23 lines
565 B
TypeScript
23 lines
565 B
TypeScript
import type { RawAxiosRequestHeaders, AxiosRequestConfig } from 'axios'
|
|
import type { RequestHeaderOptions } from '../types'
|
|
|
|
/**
|
|
*
|
|
* @param instance axios instance
|
|
* @param options axios headers options
|
|
*
|
|
* @remark 自定义 `axios` 请求头配置
|
|
*/
|
|
export const appendRequestHeaders = <T = unknown>(
|
|
instance: AxiosRequestConfig<T>,
|
|
options: RequestHeaderOptions[],
|
|
) => {
|
|
if (instance) {
|
|
const requestHeaders = instance.headers as RawAxiosRequestHeaders
|
|
|
|
options.forEach((curr) => {
|
|
requestHeaders[curr.key] = curr.value
|
|
})
|
|
}
|
|
}
|