fix(client): fix the issue where headers included in client requests were being overwritten (#6009)

This commit is contained in:
YANG QIA 2025-01-07 20:34:16 +08:00 committed by GitHub
parent dbd40f74cb
commit 452cfa376f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 3 deletions

View File

@ -93,7 +93,7 @@ export class APIClient extends APIClientSDK {
config.headers['X-With-ACL-Meta'] = true; config.headers['X-With-ACL-Meta'] = true;
const headers = this.getHeaders(); const headers = this.getHeaders();
Object.keys(headers).forEach((key) => { Object.keys(headers).forEach((key) => {
config.headers[key] = headers[key]; config.headers[key] = config.headers[key] || headers[key];
}); });
return config; return config;
}); });

View File

@ -68,4 +68,25 @@ describe('APIClient', () => {
} }
expect(apiClient.auth.role).toBeFalsy(); 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');
}
});
}); });

View File

@ -423,8 +423,8 @@ async function postCMS(tag, content, contentCN) {
}, },
data: { data: {
slug: tag, slug: tag,
title: `Nocobase ${tag}`, title: `NocoBase ${tag}`,
title_cn: `Nocobase ${tag}`, title_cn: `NocoBase ${tag}`,
content, content,
content_cn: contentCN, content_cn: contentCN,
description: `Release Note of ${tag}`, description: `Release Note of ${tag}`,