Add Accept Header on ClientTracking (#8895)

* feat: add HEADER_ACCEPT constant and update requestOptions in ClientTracking

* feat: add HEADER_ACCEPT to request headers and improve request options handling

* feat: add Accept header to performance report requests
This commit is contained in:
Lucas Reis 2025-06-06 07:42:09 -03:00 committed by GitHub
parent 9f638d11ba
commit 29e2d3ddb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 5 additions and 2 deletions

View file

@ -56,7 +56,7 @@ describe('sendPerformanceReport', () => {
it('happy path', async () => {
const {error} = await sendPerformanceReport(serverUrl, report);
expect(error).toBeFalsy();
expect(mockApiClient.post).toHaveBeenCalledWith(`${serverUrl}/api/v4/client_perf`, {body: report, headers: {}});
expect(mockApiClient.post).toHaveBeenCalledWith(`${serverUrl}/api/v4/client_perf`, {body: report, headers: {Accept: 'application/json'}});
});
it('properly returns error', async () => {

View file

@ -2,6 +2,7 @@
// See LICENSE.txt for license information.
export const HEADER_AUTH = 'Authorization';
export const HEADER_ACCEPT = 'Accept';
export const HEADER_ACCEPT_LANGUAGE = 'Accept-Language';
export const HEADER_BEARER = 'BEARER';
export const HEADER_CACHE_CONTROL = 'Cache-Control';

View file

@ -84,6 +84,8 @@ export default class ClientTracking {
getRequestHeaders(requestMethod: string) {
const headers = {...this.requestHeaders};
headers[ClientConstants.HEADER_ACCEPT]= 'application/json';
if (this.csrfToken && requestMethod.toLowerCase() !== 'get') {
headers[ClientConstants.HEADER_X_CSRF_TOKEN] = this.csrfToken;
}

View file

@ -11,6 +11,6 @@ export function getBaseReportRequest(start: number, end: number): {body: Perform
histograms: [],
counters: [],
},
headers: {},
headers: {Accept: 'application/json'},
};
}