mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
fix(client): fix the issue where headers included in client requests were being overwritten (#6009)
This commit is contained in:
parent
dbd40f74cb
commit
452cfa376f
@ -93,7 +93,7 @@ export class APIClient extends APIClientSDK {
|
||||
config.headers['X-With-ACL-Meta'] = true;
|
||||
const headers = this.getHeaders();
|
||||
Object.keys(headers).forEach((key) => {
|
||||
config.headers[key] = headers[key];
|
||||
config.headers[key] = config.headers[key] || headers[key];
|
||||
});
|
||||
return config;
|
||||
});
|
||||
|
@ -68,4 +68,25 @@ describe('APIClient', () => {
|
||||
}
|
||||
expect(apiClient.auth.role).toBeFalsy();
|
||||
});
|
||||
|
||||
test('should not overwrite headers in request', async () => {
|
||||
const instance = axios.create();
|
||||
const apiClient = new APIClient(instance);
|
||||
apiClient.app = {
|
||||
getName: () => 'test',
|
||||
} as any;
|
||||
apiClient.auth.authenticator = 'basic';
|
||||
try {
|
||||
await apiClient.request({
|
||||
method: 'GET',
|
||||
url: '/api/test',
|
||||
headers: {
|
||||
'X-Authenticator': 'test',
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
expect(err).toBeDefined();
|
||||
expect(err.config.headers['X-Authenticator']).toBe('test');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -423,8 +423,8 @@ async function postCMS(tag, content, contentCN) {
|
||||
},
|
||||
data: {
|
||||
slug: tag,
|
||||
title: `Nocobase ${tag}`,
|
||||
title_cn: `Nocobase ${tag}`,
|
||||
title: `NocoBase ${tag}`,
|
||||
title_cn: `NocoBase ${tag}`,
|
||||
content,
|
||||
content_cn: contentCN,
|
||||
description: `Release Note of ${tag}`,
|
||||
|
Loading…
x
Reference in New Issue
Block a user