diff --git a/src/adpater/createAdapter.ts b/src/adpater/createAdapter.ts index fa42482..192343b 100644 --- a/src/adpater/createAdapter.ts +++ b/src/adpater/createAdapter.ts @@ -270,6 +270,7 @@ export function createAdapter(platform: AxiosAdapterPlatform) { ): AxiosAdapterBaseOptions { return { ...config, + header: config.headers, success(response) { transformResponse(response); config.success(response); diff --git a/src/request/request.ts b/src/request/request.ts index 7e3a2d4..e52e13b 100644 --- a/src/request/request.ts +++ b/src/request/request.ts @@ -24,20 +24,16 @@ import { generateType } from './generateType'; */ export function request(config: AxiosRequestConfig) { return new Promise((resolve, reject) => { - const { adapter, url, method, cancelToken } = config; - const adapterConfig: AxiosAdapterRequestConfig = { - ...config, - url: url!, + ...(config as AxiosAdapterRequestConfig), type: generateType(config), - method: method as AxiosAdapterRequestMethod, success, fail, }; let adapterTask: AxiosAdapterPlatformTask; try { - adapterTask = adapter!(adapterConfig); + adapterTask = config.adapter!(adapterConfig); } catch (err) { fail({ status: 400, @@ -86,6 +82,7 @@ export function request(config: AxiosRequestConfig) { tryToggleProgressUpdate(adapterConfig, adapterTask.onProgressUpdate); } + const { cancelToken } = config; if (isCancelToken(cancelToken)) { cancelToken.onCancel((reason) => { if (isPlainObject(adapterTask)) { diff --git a/test/adpater/createAdapter.test.ts b/test/adpater/createAdapter.test.ts index 45cf8a8..73563c9 100644 --- a/test/adpater/createAdapter.test.ts +++ b/test/adpater/createAdapter.test.ts @@ -81,6 +81,9 @@ describe('src/adapter/createAdapter.ts', () => { expect(p.request.mock.calls[0][0]).toMatchInlineSnapshot(` { "fail": [Function], + "header": { + "Accept": "application/json, text/plain, */*", + }, "headers": { "Accept": "application/json, text/plain, */*", }, @@ -109,6 +112,9 @@ describe('src/adapter/createAdapter.ts', () => { "id": 1, "user": "test", }, + "header": { + "Accept": "application/json, text/plain, */*", + }, "headers": { "Accept": "application/json, text/plain, */*", }, @@ -126,6 +132,9 @@ describe('src/adapter/createAdapter.ts', () => { { "fail": [Function], "filePath": "/path/file", + "header": { + "Accept": "application/json, text/plain, */*", + }, "headers": { "Accept": "application/json, text/plain, */*", },