Skip to content

Commit c0ca900

Browse files
committed
fix: 适配器请求头丢失
#43
1 parent 968bbb7 commit c0ca900

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/adpater/createAdapter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ export function createAdapter(platform: AxiosAdapterPlatform) {
270270
): AxiosAdapterBaseOptions {
271271
return {
272272
...config,
273+
header: config.headers,
273274
success(response) {
274275
transformResponse(response);
275276
config.success(response);

src/request/request.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@ import { generateType } from './generateType';
2424
*/
2525
export function request(config: AxiosRequestConfig) {
2626
return new Promise<AxiosResponse>((resolve, reject) => {
27-
const { adapter, url, method, cancelToken } = config;
28-
2927
const adapterConfig: AxiosAdapterRequestConfig = {
30-
...config,
31-
url: url!,
28+
...(config as AxiosAdapterRequestConfig),
3229
type: generateType(config),
33-
method: method as AxiosAdapterRequestMethod,
3430
success,
3531
fail,
3632
};
3733

3834
let adapterTask: AxiosAdapterPlatformTask;
3935
try {
40-
adapterTask = adapter!(adapterConfig);
36+
adapterTask = config.adapter!(adapterConfig);
4137
} catch (err) {
4238
fail({
4339
status: 400,
@@ -86,6 +82,7 @@ export function request(config: AxiosRequestConfig) {
8682
tryToggleProgressUpdate(adapterConfig, adapterTask.onProgressUpdate);
8783
}
8884

85+
const { cancelToken } = config;
8986
if (isCancelToken(cancelToken)) {
9087
cancelToken.onCancel((reason) => {
9188
if (isPlainObject(adapterTask)) {

test/adpater/createAdapter.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ describe('src/adapter/createAdapter.ts', () => {
8181
expect(p.request.mock.calls[0][0]).toMatchInlineSnapshot(`
8282
{
8383
"fail": [Function],
84+
"header": {
85+
"Accept": "application/json, text/plain, */*",
86+
},
8487
"headers": {
8588
"Accept": "application/json, text/plain, */*",
8689
},
@@ -109,6 +112,9 @@ describe('src/adapter/createAdapter.ts', () => {
109112
"id": 1,
110113
"user": "test",
111114
},
115+
"header": {
116+
"Accept": "application/json, text/plain, */*",
117+
},
112118
"headers": {
113119
"Accept": "application/json, text/plain, */*",
114120
},
@@ -126,6 +132,9 @@ describe('src/adapter/createAdapter.ts', () => {
126132
{
127133
"fail": [Function],
128134
"filePath": "/path/file",
135+
"header": {
136+
"Accept": "application/json, text/plain, */*",
137+
},
129138
"headers": {
130139
"Accept": "application/json, text/plain, */*",
131140
},

0 commit comments

Comments
 (0)