From f8771297b05872bf887301ec2e93ed5230afb057 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Mon, 28 Aug 2023 04:30:11 +0800 Subject: [PATCH] pass `Blob` as body --- lib/methods.mjs | 2 +- lib/sri.mjs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/methods.mjs b/lib/methods.mjs index 5309d5f..b730975 100644 --- a/lib/methods.mjs +++ b/lib/methods.mjs @@ -41,7 +41,7 @@ const GET = async (url, { headers, integrity, signal }) => { async body => [ body, await statsAsOptions( - Object.assign(stats, { size: BigInt(body.byteLength) }), + Object.assign(stats, { size: BigInt(body.size) }), { status: 206 } ), ] diff --git a/lib/sri.mjs b/lib/sri.mjs index 51ea44f..606f75d 100644 --- a/lib/sri.mjs +++ b/lib/sri.mjs @@ -6,8 +6,7 @@ const algoFromSRI = new Map([ ]); const validatedBody = async (integrity, body) => { - // TODO: use blob directly, when it wouldn't break in Response - body = await new Blob(body).arrayBuffer(); + body = new Blob(body); if (!integrity) return body; @@ -16,7 +15,7 @@ const validatedBody = async (integrity, body) => { const [algo, sign] = integrity.trim().split('-'); const hash = Buffer.from(await crypto.subtle.digest( algoFromSRI.get(algo.toLowerCase()) ?? algo, - body + await body.arrayBuffer() )).toString('base64'); if (sign !== hash) throw new TypeError('Integrity mismatch');