Skip to content

Commit

Permalink
fix(platform-response-filter): update getContentType detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Mar 24, 2024
1 parent b4e01e7 commit c18add2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("getContentType", () => {
beforeEach(() => PlatformTest.create());
afterEach(() => PlatformTest.reset());

it("should return the content type (undefined)", () => {
it("should return the content type (application/json) if the data is an object", () => {
class TestController {
@Get("/")
get() {}
Expand All @@ -22,6 +22,22 @@ describe("getContentType", () => {
ctx
);

expect(result).toEqual("application/json");
});

it("should return the content type (Buffer -> undefined)", () => {
class TestController {
@Get("/")
get(): Buffer {
return Buffer.from("test");
}
}

const ctx = PlatformTest.createRequestContext();
ctx.endpoint = EndpointMetadata.get(TestController, "get");

const result = getContentType(Buffer.from("test"), ctx);

expect(result).toEqual(undefined);
});
it("should return the content type (object - application/json)", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function getContentType(data: any, ctx: BaseContext) {
return "text/html";
}

if (contentType === "" && isObject(data)) {
if (contentType === "" && isObject(data) && !Buffer.isBuffer(data)) {
return "application/json";
}
}

0 comments on commit c18add2

Please sign in to comment.