Skip to content

Commit

Permalink
fix: fixes an issue where OFREP does not send content type headers (#882
Browse files Browse the repository at this point in the history
)

Signed-off-by: Lukas Reining <lukas.reining@codecentric.de>
  • Loading branch information
lukas-reining committed Apr 16, 2024
1 parent 5c22142 commit b3289e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libs/shared/ofrep-core/src/lib/api/ofrep-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ export class OFREPApi {
evaluationRequest?: EvaluationRequest,
options?: RequestOptions,
): Promise<OFREPApiEvaluationResult> {
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 ?? {}),
});
Expand All @@ -126,8 +130,12 @@ export class OFREPApi {
evaluationRequest?: EvaluationRequest,
options?: RequestOptions,
): Promise<OFREPApiBulkEvaluationResult> {
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 ?? {}),
});
Expand Down
10 changes: 10 additions & 0 deletions libs/shared/ofrep-core/src/test/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit b3289e5

Please sign in to comment.