Skip to content

Commit fa1128a

Browse files
serhalpryansolid
andauthored
fix: handle request body streaming with latest netlify preset (#1705)
* fix: handle request body streaming with latest netlify preset See #1673. * add changeset --------- Co-authored-by: Ryan Carniato <ryansolid@gmail.com>
1 parent dbfc569 commit fa1128a

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

.changeset/violet-snakes-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fake-scope/fake-pkg": patch
3+
---
4+
5+
fix: handle request body streaming with latest netlify preset

packages/start/src/runtime/server-handler.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,17 @@ async function handleServerFunction(h3Event: HTTPEvent) {
128128
// This should never be the case in "proper" Nitro presets since node.req has to be IncomingMessage,
129129
// But the new azure-functions preset for some reason uses a ReadableStream in node.req (#1521)
130130
const isReadableStream = h3Request instanceof ReadableStream;
131-
const isH3EventBodyStreamLocked = isReadableStream && h3Request.locked;
131+
const hasReadableStream = h3Request.body instanceof ReadableStream;
132+
const isH3EventBodyStreamLocked =
133+
(isReadableStream && h3Request.locked) || (hasReadableStream && h3Request.body.locked);
132134
const requestBody = isReadableStream ? h3Request : h3Request.body;
133135

134136
if (
135137
contentType?.startsWith("multipart/form-data") ||
136138
contentType?.startsWith("application/x-www-form-urlencoded")
137139
) {
138140
// workaround for https://github.com/unjs/nitro/issues/1721
139-
// (issue only in edge runtimes)
141+
// (issue only in edge runtimes and netlify preset)
140142
parsed.push(
141143
await (isH3EventBodyStreamLocked
142144
? request
@@ -147,7 +149,7 @@ async function handleServerFunction(h3Event: HTTPEvent) {
147149
// parsed.push(await request.formData);
148150
} else if (contentType?.startsWith("application/json")) {
149151
// workaround for https://github.com/unjs/nitro/issues/1721
150-
// (issue only in edge runtimes)
152+
// (issue only in edge runtimes and netlify preset)
151153
const tmpReq = isH3EventBodyStreamLocked
152154
? request
153155
: new Request(request, { ...request, body: requestBody });

0 commit comments

Comments
 (0)