fix: 适配器请求头丢失

#43
pull/49/head
zjx0905 2023-04-23 14:23:06 +08:00
parent 968bbb775e
commit c0ca9001d2
3 changed files with 13 additions and 6 deletions

View File

@ -270,6 +270,7 @@ export function createAdapter(platform: AxiosAdapterPlatform) {
): AxiosAdapterBaseOptions {
return {
...config,
header: config.headers,
success(response) {
transformResponse(response);
config.success(response);

View File

@ -24,20 +24,16 @@ import { generateType } from './generateType';
*/
export function request(config: AxiosRequestConfig) {
return new Promise<AxiosResponse>((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)) {

View File

@ -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, */*",
},