Skip to content

Commit

Permalink
Specify Content-Type as application/json unless specified in Accept
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronaldo Macapobre committed Feb 12, 2025
1 parent 968d86d commit 8600e97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion aws/tests/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ describe("sanitizeHeaders", () => {
applicationCd: "app123",
correlationId: "12345",
Accept: "application/octet-stream",
"Content-Type": "application/octet-stream",
});
});

it("should return an empty object if no allowed headers are present", () => {
const headers = { unauthorizedHeader: "shouldBeRemoved" };
expect(sanitizeHeaders(headers)).toEqual({});
expect(sanitizeHeaders(headers)).toEqual({
"Content-Type": "application/json",
});
});
});

Expand Down
6 changes: 6 additions & 0 deletions aws/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export const sanitizeHeaders = (
}
}

// Specify Content-Type as application/json unless specified in Accept
filteredHeaders["Content-Type"] =
filteredHeaders["Accept"] === "application/octet-stream"
? "application/octet-stream"
: "application/json";

return filteredHeaders;
};

Expand Down

0 comments on commit 8600e97

Please sign in to comment.