Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions packages/duckdb-wasm/src/bindings/runtime_browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
xhr.send(null);

// Supports range requests
contentLength = xhr.getResponseHeader('Content-Length');
contentLength = null;
try { contentLength = xhr.getResponseHeader('Content-Length'); } catch (e: any) {console.warn(`Failed to get Content-Length on request`);}
if (contentLength !== null && xhr.status == 206) {
const result = mod._malloc(2 * 8);
mod.HEAPF64[(result >> 3) + 0] = +contentLength;
Expand Down Expand Up @@ -288,8 +289,10 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
xhr.responseType = 'arraybuffer';
xhr.setRequestHeader('Range', `bytes=0-0`);
xhr.send(null);
const contentRange = xhr.getResponseHeader('Content-Range')?.split('/')[1];
const contentLength2 = xhr.getResponseHeader('Content-Length');
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;

Comment on lines -291 to 293
Copy link

@jbruggem jbruggem Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlopi I stumbled on this changed while trying to understand why duckdb-wasm seemed unhappy with the behaviour of my server.

This change means that the code now looks for the actually content length in the Content-Length header (by splitting on /) instead of the previous behaviour of looking for it in the Content-Range.

I believe the pre-diff behaviour is correct, as Content-Length shouldn't contain a / and shouldn't send the full content length.

Should I open a PR to suggest a fix ?

See:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! thanks for digging in, this looks like it's a problem, not great, a PR with a suggested fix would be great!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks for the quick reply ! Here's a PR: #2123

I tried to stay as close to the original code as I could

let presumedLength = null;
if (contentRange !== undefined) {
Expand All @@ -308,7 +311,8 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
head.send(null);

// Supports range requests
contentLength = head.getResponseHeader('Content-Length');
contentLength = null;
try { contentLength = head.getResponseHeader('Content-Length'); } catch (e: any) {console.warn(`Failed to get Content-Length on request`);}
if (contentLength !== null && +contentLength > 1) {
presumedLength = contentLength;
}
Expand Down Expand Up @@ -454,7 +458,8 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
console.log(`HEAD and GET requests failed: ${path}`);
return 0;
}
const contentLength = xhr2.getResponseHeader('Content-Length');
let contentLength = null;
try { contentLength = xhr2.getResponseHeader('Content-Length'); } catch (e: any) {console.warn(`Failed to get Content-Length on request`);}
if (contentLength && +contentLength > 1) {
console.warn(
`Range request for ${path} did not return a partial response: ${xhr2.status} "${xhr2.statusText}"`,
Expand Down