Skip to content

Commit

Permalink
fix: fix response binary content handling (#526)
Browse files Browse the repository at this point in the history
* fix response binary content headers

* Create alacroix.md

---------

Co-authored-by: conico974 <[email protected]>
  • Loading branch information
alacroix and conico974 authored Oct 3, 2024
1 parent 9fceedb commit b5bfb5d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/alacroix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

Fix response binary content handling
8 changes: 3 additions & 5 deletions packages/open-next/src/core/routing/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ export function convertRes(res: OpenNextNodeResponse): InternalResult {
// When using HEAD requests, it seems that flushHeaders is not called, not sure why
// Probably some kind of race condition
const headers = parseHeaders(res.getFixedHeaders());
const isBase64Encoded = isBinaryContentType(
Array.isArray(headers["content-type"])
? headers["content-type"][0]
: headers["content-type"],
);
const isBase64Encoded =
isBinaryContentType(headers["content-type"]) ||
!!headers["content-encoding"];
// We cannot convert the OpenNextNodeResponse to a ReadableStream directly
// You can look in the `aws-lambda.ts` file for some context
const body = Readable.toWeb(Readable.from(res.getBody()));
Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/http/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const parseHeaders = (
if (value === undefined) {
continue;
} else {
result[key] = convertHeader(value);
result[key.toLowerCase()] = convertHeader(value);
}
}

Expand Down

0 comments on commit b5bfb5d

Please sign in to comment.