Skip to content

Commit b5bfb5d

Browse files
alacroixconico974
andauthored
fix: fix response binary content handling (#526)
* fix response binary content headers * Create alacroix.md --------- Co-authored-by: conico974 <[email protected]>
1 parent 9fceedb commit b5bfb5d

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

.changeset/alacroix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
Fix response binary content handling

packages/open-next/src/core/routing/util.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,9 @@ export function convertRes(res: OpenNextNodeResponse): InternalResult {
7676
// When using HEAD requests, it seems that flushHeaders is not called, not sure why
7777
// Probably some kind of race condition
7878
const headers = parseHeaders(res.getFixedHeaders());
79-
const isBase64Encoded = isBinaryContentType(
80-
Array.isArray(headers["content-type"])
81-
? headers["content-type"][0]
82-
: headers["content-type"],
83-
);
79+
const isBase64Encoded =
80+
isBinaryContentType(headers["content-type"]) ||
81+
!!headers["content-encoding"];
8482
// We cannot convert the OpenNextNodeResponse to a ReadableStream directly
8583
// You can look in the `aws-lambda.ts` file for some context
8684
const body = Readable.toWeb(Readable.from(res.getBody()));

packages/open-next/src/http/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const parseHeaders = (
1212
if (value === undefined) {
1313
continue;
1414
} else {
15-
result[key] = convertHeader(value);
15+
result[key.toLowerCase()] = convertHeader(value);
1616
}
1717
}
1818

0 commit comments

Comments
 (0)