From 3884d6e02e9e5a11bc1dd8d28392a7fba18498c9 Mon Sep 17 00:00:00 2001 From: Jehan Bruggeman Date: Wed, 5 Nov 2025 09:37:25 +0100 Subject: [PATCH] Restore previous behaviour of getting full doc size from Content-Range when available --- .../src/bindings/runtime_browser.ts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/duckdb-wasm/src/bindings/runtime_browser.ts b/packages/duckdb-wasm/src/bindings/runtime_browser.ts index 34a1ed165..3b59d7b4f 100644 --- a/packages/duckdb-wasm/src/bindings/runtime_browser.ts +++ b/packages/duckdb-wasm/src/bindings/runtime_browser.ts @@ -296,14 +296,17 @@ export const BROWSER_RUNTIME: DuckDBRuntime & { xhr.responseType = 'arraybuffer'; xhr.setRequestHeader('Range', `bytes=0-0`); xhr.send(null); - let actualContentLength = null; - try { actualContentLength = xhr.getResponseHeader('Content-Length'); } catch (e: any) {console.warn(`Failed to get Content-Length on request`);} - const contentRange = actualContentLength?.split('/')[1]; - const contentLength2 = actualContentLength; + + let contentLength = null; + try { contentLength = xhr.getResponseHeader('Content-Length'); } catch (e: any) {console.warn(`Failed to get Content-Length on request`);} + + let contentRange = null; + try { contentRange = xhr.getResponseHeader('Content-Range'); } catch (e: any) {console.warn(`Failed to get Content-Range on request`);} + const fullLengthFromRange = contentRange?.split('/')[1] || null; let presumedLength = null; - if (contentRange !== undefined) { - presumedLength = contentRange; + if (fullLengthFromRange !== null) { + presumedLength = fullLengthFromRange; } else if (!file.reliableHeadRequests) { // Send a dummy HEAD request with range protocol // -> good IFF status is 206 and contentLenght is present @@ -327,8 +330,8 @@ export const BROWSER_RUNTIME: DuckDBRuntime & { if ( xhr.status == 206 && - contentLength2 !== null && - +contentLength2 == 1 && + fullLengthFromRange !== null && + +fullLengthFromRange == 1 && presumedLength !== null ) { const result = mod._malloc(3 * 8); @@ -341,9 +344,9 @@ export const BROWSER_RUNTIME: DuckDBRuntime & { } if ( xhr.status == 200 && - contentLength2 !== null && + fullLengthFromRange !== null && contentLength !== null && - +contentLength2 == +contentLength + +fullLengthFromRange == +contentLength ) { console.warn(`fall back to full HTTP read for: ${file.dataUrl}`); const data = mod._malloc(xhr.response.byteLength);