File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
packages/open-next/src/adapters Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " open-next " : patch
3
+ ---
4
+
5
+ server: support ArrayBuffer response
Original file line number Diff line number Diff line change @@ -11,24 +11,29 @@ const BODY = Symbol();
11
11
const HEADERS = Symbol ( ) ;
12
12
13
13
function getString ( data ) {
14
+ // Note: use `ArrayBuffer.isView()` to check for Uint8Array. Using
15
+ // `instanceof Uint8Array` returns false in some cases. For example,
16
+ // when the buffer is created in middleware and passed to NextServer.
14
17
if ( Buffer . isBuffer ( data ) ) {
15
18
return data . toString ( "utf8" ) ;
19
+ } else if ( ArrayBuffer . isView ( data ) ) {
20
+ return Buffer . from ( data ) . toString ( "utf8" ) ;
16
21
} else if ( typeof data === "string" ) {
17
22
return data ;
18
23
} else {
19
- throw new Error ( `response.write () of unexpected type: ${ typeof data } ` ) ;
24
+ throw new Error ( `response.getString () of unexpected type: ${ typeof data } ` ) ;
20
25
}
21
26
}
22
27
23
28
function addData ( stream , data ) {
24
29
if (
25
30
Buffer . isBuffer ( data ) ||
26
- typeof data === "string" ||
27
- data instanceof Uint8Array
31
+ ArrayBuffer . isView ( data ) ||
32
+ typeof data === "string"
28
33
) {
29
34
stream [ BODY ] . push ( Buffer . from ( data ) ) ;
30
35
} else {
31
- throw new Error ( `response.write () of unexpected type: ${ typeof data } ` ) ;
36
+ throw new Error ( `response.addData () of unexpected type: ${ typeof data } ` ) ;
32
37
}
33
38
}
34
39
You can’t perform that action at this time.
0 commit comments