From b8d4ab0e12a810b0f0e330575878421c604ab4be Mon Sep 17 00:00:00 2001 From: Alisson Fabiano Date: Wed, 19 Oct 2022 10:40:28 +0100 Subject: [PATCH] fixed reading headers Signed-off-by: Alisson Fabiano --- .../src/api/TechInsightsClient.ts | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/plugins/tech-insights/src/api/TechInsightsClient.ts b/plugins/tech-insights/src/api/TechInsightsClient.ts index afd214d581..6e85769b34 100644 --- a/plugins/tech-insights/src/api/TechInsightsClient.ts +++ b/plugins/tech-insights/src/api/TechInsightsClient.ts @@ -82,9 +82,6 @@ export class TechInsightsClient implements TechInsightsApi { { method: 'POST', body: JSON.stringify(requestBody), - headers: { - 'Content-Type': 'application/json', - }, }, ); } @@ -101,9 +98,6 @@ export class TechInsightsClient implements TechInsightsApi { return this.api('/checks/run', { method: 'POST', body: JSON.stringify(requestBody), - headers: { - 'Content-Type': 'application/json', - }, }); } @@ -111,14 +105,18 @@ export class TechInsightsClient implements TechInsightsApi { const url = await this.discoveryApi.getBaseUrl('tech-insights'); const { token } = await this.identityApi.getCredentials(); - const request = new Request(`${url}${path}`, init); - if (!request.headers.has('content-type')) { - request.headers.set('content-type', 'application/json'); - } - if (token && !request.headers.has('authorization')) { - request.headers.set('authorization', `Bearer ${token}`); + const headers: HeadersInit = new Headers(init?.headers); + if (!headers.has('content-type')) + headers.set('content-type', 'application/json'); + if (token && !headers.has('authorization')) { + headers.set('authorization', `Bearer ${token}`); } + const request = new Request(`${url}${path}`, { + ...init, + headers, + }); + return fetch(request).then(async response => { if (!response.ok) { throw await ResponseError.fromResponse(response);