Skip to content

Commit cff6ced

Browse files
authored
Merge pull request #381 from csfloat/fix/content-length-fallback
Fallback to Blob Response Body Size if No `Content-Length`
2 parents 733ebce + 55e54fc commit cff6ced

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/offscreen/handlers/notary_prove.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,16 @@ async function calculateResponseSize(
196196

197197
const contentLength = response.headers.get('content-length');
198198

199-
if (!contentLength) {
200-
throw new Error('no content length in response headers');
199+
let bodySize: number;
200+
201+
if (contentLength) {
202+
bodySize = parseInt(contentLength, 10);
203+
} else {
204+
console.debug('fallback to measuring response blob due to no content-length header');
205+
const blob = await response.blob();
206+
bodySize = blob.size;
201207
}
202208

203-
const bodySize = parseInt(contentLength, 10);
204-
205209
return headersSize + bodySize;
206210
}
207211

0 commit comments

Comments
 (0)