File tree Expand file tree Collapse file tree 3 files changed +24
-12
lines changed Expand file tree Collapse file tree 3 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -102,9 +102,10 @@ export function convertRes(res: OpenNextNodeResponse): InternalResult {
102
102
// When using HEAD requests, it seems that flushHeaders is not called, not sure why
103
103
// Probably some kind of race condition
104
104
const headers = parseHeaders ( res . getFixedHeaders ( ) ) ;
105
+ const contentType = headers [ "content-type" ] ;
105
106
const isBase64Encoded =
106
- isBinaryContentType ( headers [ "content-type" ] ) ||
107
- ! ! headers [ "content-encoding" ] ;
107
+ typeof contentType === "string" &&
108
+ ( isBinaryContentType ( contentType ) || ! ! headers [ "content-encoding" ] ) ;
108
109
// We cannot convert the OpenNextNodeResponse to a ReadableStream directly
109
110
// You can look in the `aws-lambda.ts` file for some context
110
111
const body = Readable . toWeb ( Readable . from ( res . getBody ( ) ) ) ;
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import { Transform } from "node:stream";
10
10
11
11
import type { StreamCreator } from "types/open-next" ;
12
12
import { debug } from "../adapters/logger" ;
13
- import { parseHeaders , parseSetCookieHeader } from "./util" ;
13
+ import { flattenHeaders , parseSetCookieHeader } from "./util" ;
14
14
15
15
const SET_COOKIE_HEADER = "set-cookie" ;
16
16
const CANNOT_BE_USED = "This cannot be used in OpenNext" ;
@@ -184,7 +184,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
184
184
// We need to fix the set-cookie header here
185
185
this . headers [ SET_COOKIE_HEADER ] = this . _cookies ;
186
186
187
- const parsedHeaders = parseHeaders ( this . headers ) ;
187
+ const parsedHeaders = flattenHeaders ( this . headers ) ;
188
188
189
189
// We need to remove the set-cookie header from the parsed headers because
190
190
// 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";
3
3
export const parseHeaders = (
4
4
headers ?: http . OutgoingHttpHeader [ ] | http . OutgoingHttpHeaders ,
5
5
) => {
6
- const result : Record < string , string > = { } ;
6
+ const result : Record < string , string | string [ ] > = { } ;
7
7
if ( ! headers ) {
8
8
return result ;
9
9
}
@@ -12,20 +12,31 @@ export const parseHeaders = (
12
12
if ( value === undefined ) {
13
13
continue ;
14
14
}
15
- result [ key . toLowerCase ( ) ] = convertHeader ( value ) ;
15
+ result [ key . toLowerCase ( ) ] =
16
+ typeof value === "number" ? String ( value ) : value ;
16
17
}
17
18
18
19
return result ;
19
20
} ;
20
21
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 ;
24
28
}
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 ) ;
27
37
}
28
- return String ( header ) ;
38
+
39
+ return result ;
29
40
} ;
30
41
31
42
/**
You can’t perform that action at this time.
0 commit comments