File tree Expand file tree Collapse file tree 3 files changed +23
-11
lines changed Expand file tree Collapse file tree 3 files changed +23
-11
lines changed Original file line number Diff line number Diff line change @@ -102,8 +102,9 @@ export function convertRes(res: OpenNextNodeResponse): InternalResult {
102102 // When using HEAD requests, it seems that flushHeaders is not called, not sure why
103103 // Probably some kind of race condition
104104 const headers = parseHeaders ( res . getFixedHeaders ( ) ) ;
105+ const contentType = headers [ "content-type" ] ;
105106 const isBase64Encoded =
106- isBinaryContentType ( headers [ "content-type" ] ) ||
107+ ( typeof contentType === "string" && isBinaryContentType ( contentType ) ) ||
107108 ! ! headers [ "content-encoding" ] ;
108109 // We cannot convert the OpenNextNodeResponse to a ReadableStream directly
109110 // You can look in the `aws-lambda.ts` file for some context
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import { Transform } from "node:stream";
1010
1111import type { StreamCreator } from "types/open-next" ;
1212import { debug } from "../adapters/logger" ;
13- import { parseHeaders , parseSetCookieHeader } from "./util" ;
13+ import { flattenHeaders , parseSetCookieHeader } from "./util" ;
1414
1515const SET_COOKIE_HEADER = "set-cookie" ;
1616const CANNOT_BE_USED = "This cannot be used in OpenNext" ;
@@ -184,7 +184,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
184184 // We need to fix the set-cookie header here
185185 this . headers [ SET_COOKIE_HEADER ] = this . _cookies ;
186186
187- const parsedHeaders = parseHeaders ( this . headers ) ;
187+ const parsedHeaders = flattenHeaders ( this . headers ) ;
188188
189189 // We need to remove the set-cookie header from the parsed headers because
190190 // it does not handle multiple set-cookie headers properly
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import type http from "node:http";
33export const parseHeaders = (
44 headers ?: http . OutgoingHttpHeader [ ] | http . OutgoingHttpHeaders ,
55) => {
6- const result : Record < string , string > = { } ;
6+ const result : Record < string , string | string [ ] > = { } ;
77 if ( ! headers ) {
88 return result ;
99 }
@@ -12,20 +12,31 @@ export const parseHeaders = (
1212 if ( value === undefined ) {
1313 continue ;
1414 }
15- result [ key . toLowerCase ( ) ] = convertHeader ( value ) ;
15+ result [ key . toLowerCase ( ) ] =
16+ typeof value === "number" ? String ( value ) : value ;
1617 }
1718
1819 return result ;
1920} ;
2021
21- export const convertHeader = ( header : http . OutgoingHttpHeader ) => {
22- if ( typeof header === "string" ) {
23- return header ;
22+ export const flattenHeaders = (
23+ headers ?: http . OutgoingHttpHeader [ ] | http . OutgoingHttpHeaders ,
24+ ) => {
25+ const result : Record < string , string > = { } ;
26+ if ( ! headers ) {
27+ return result ;
2428 }
25- if ( Array . isArray ( header ) ) {
26- return header . join ( "," ) ;
29+
30+ for ( const [ key , value ] of Object . entries ( headers ) ) {
31+ if ( value === undefined ) {
32+ continue ;
33+ }
34+ result [ key . toLowerCase ( ) ] = Array . isArray ( value )
35+ ? value . join ( "," )
36+ : String ( value ) ;
2737 }
28- return String ( header ) ;
38+
39+ return result ;
2940} ;
3041
3142/**
You can’t perform that action at this time.
0 commit comments