From 2c0b0e45b72ef1b5d7fa95e1e110d07ddbc720f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20W=C3=A4rting?= Date: Mon, 5 Jul 2021 15:34:37 +0200 Subject: refactor: asynchronous blob backing store (#10969) Co-authored-by: Luca Casonato --- extensions/fetch/26_fetch.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'extensions/fetch/26_fetch.js') diff --git a/extensions/fetch/26_fetch.js b/extensions/fetch/26_fetch.js index 47b07be0b..a33187344 100644 --- a/extensions/fetch/26_fetch.js +++ b/extensions/fetch/26_fetch.js @@ -152,15 +152,18 @@ if (req.body !== null) { if (req.body.streamOrStatic instanceof ReadableStream) { - if (req.body.length === null) { + if (req.body.length === null || req.body.source instanceof Blob) { reqBody = req.body.stream; } else { const reader = req.body.stream.getReader(); const r1 = await reader.read(); - if (r1.done) throw new TypeError("Unreachable"); - reqBody = r1.value; - const r2 = await reader.read(); - if (!r2.done) throw new TypeError("Unreachable"); + if (r1.done) { + reqBody = new Uint8Array(0); + } else { + reqBody = r1.value; + const r2 = await reader.read(); + if (!r2.done) throw new TypeError("Unreachable"); + } } } else { req.body.streamOrStatic.consumed = true; @@ -174,6 +177,7 @@ headers: req.headerList, clientRid: req.clientRid, hasBody: reqBody !== null, + bodyLength: req.body?.length, }, reqBody instanceof Uint8Array ? reqBody : null); function onAbort() { -- cgit v1.2.3