From b3289e5083e97946f4ab62a6f2f10bb1402e7a55 Mon Sep 17 00:00:00 2001 From: Lukas Reining Date: Tue, 16 Apr 2024 12:09:54 +0200 Subject: [PATCH] fix: fixes an issue where OFREP does not send content type headers (#882) Signed-off-by: Lukas Reining --- libs/shared/ofrep-core/src/lib/api/ofrep-api.ts | 8 ++++++++ libs/shared/ofrep-core/src/test/handlers.ts | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/libs/shared/ofrep-core/src/lib/api/ofrep-api.ts b/libs/shared/ofrep-core/src/lib/api/ofrep-api.ts index 6a3fed56f..2e5dca033 100644 --- a/libs/shared/ofrep-core/src/lib/api/ofrep-api.ts +++ b/libs/shared/ofrep-core/src/lib/api/ofrep-api.ts @@ -106,8 +106,12 @@ export class OFREPApi { evaluationRequest?: EvaluationRequest, options?: RequestOptions, ): Promise { + const headers = new Headers(options?.headers); + headers.append('Content-Type', 'application/json; charset=utf-8'); + const request = new Request(`${this.baseUrl}/ofrep/v1/evaluate/flags/${flagKey}`, { ...options, + headers, method: 'POST', body: JSON.stringify(evaluationRequest ?? {}), }); @@ -126,8 +130,12 @@ export class OFREPApi { evaluationRequest?: EvaluationRequest, options?: RequestOptions, ): Promise { + const headers = new Headers(options?.headers); + headers.append('Content-Type', 'application/json; charset=utf-8'); + const request = new Request(`${this.baseUrl}/ofrep/v1/evaluate/flags`, { ...options, + headers: headers, method: 'POST', body: JSON.stringify(evaluationRequest ?? {}), }); diff --git a/libs/shared/ofrep-core/src/test/handlers.ts b/libs/shared/ofrep-core/src/test/handlers.ts index 199aa8047..d3b7ffcd5 100644 --- a/libs/shared/ofrep-core/src/test/handlers.ts +++ b/libs/shared/ofrep-core/src/test/handlers.ts @@ -17,6 +17,11 @@ export const handlers = [ throw HttpResponse.text(undefined, { status: 400 }); } + const contentTypeHeader = info.request.headers.get('Content-Type'); + if (contentTypeHeader?.toLowerCase() !== 'application/json; charset=utf-8') { + throw HttpResponse.text('Wrong content type', { status: 415 }); + } + const authHeader = info.request.headers.get('Authorization'); const expectedAuthHeader = requestBody.context?.['expectedAuthHeader'] ?? null; @@ -115,6 +120,11 @@ export const handlers = [ throw HttpResponse.text(undefined, { status: 400 }); } + const contentTypeHeader = info.request.headers.get('Content-Type'); + if (contentTypeHeader?.toLowerCase() !== 'application/json; charset=utf-8') { + throw HttpResponse.text('Wrong content type', { status: 415 }); + } + const authHeader = info.request.headers.get('Authorization'); const expectedAuthHeader = requestBody.context?.['expectedAuthHeader'] ?? null;