Skip to content

Commit 51b5481

Browse files
committed
Avoid bubbling erros on getResponseHeader on forbidden headers
1 parent 88133f2 commit 51b5481

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/duckdb-wasm/src/bindings/runtime_browser.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
258258
xhr.send(null);
259259

260260
// Supports range requests
261-
contentLength = xhr.getResponseHeader('Content-Length');
261+
contentLength = null;
262+
try { contentLength = xhr.getResponseHeader('Content-Length'); } catch (e: any) {console.warn(`Failed to get Content-Length on request`);}
262263
if (contentLength !== null && xhr.status == 206) {
263264
const result = mod._malloc(2 * 8);
264265
mod.HEAPF64[(result >> 3) + 0] = +contentLength;
@@ -288,8 +289,10 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
288289
xhr.responseType = 'arraybuffer';
289290
xhr.setRequestHeader('Range', `bytes=0-0`);
290291
xhr.send(null);
291-
const contentRange = xhr.getResponseHeader('Content-Range')?.split('/')[1];
292-
const contentLength2 = xhr.getResponseHeader('Content-Length');
292+
let actualContentLength = null;
293+
try { actualContentLength = xhr.getResponseHeader('Content-Length'); } catch (e: any) {console.warn(`Failed to get Content-Length on request`);}
294+
const contentRange = actualContentLength?.split('/')[1];
295+
const contentLength2 = actualContentLength;
293296

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

310313
// Supports range requests
311-
contentLength = head.getResponseHeader('Content-Length');
314+
contentLength = null;
315+
try { contentLength = head.getResponseHeader('Content-Length'); } catch (e: any) {console.warn(`Failed to get Content-Length on request`);}
312316
if (contentLength !== null && +contentLength > 1) {
313317
presumedLength = contentLength;
314318
}
@@ -454,7 +458,8 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
454458
console.log(`HEAD and GET requests failed: ${path}`);
455459
return 0;
456460
}
457-
const contentLength = xhr2.getResponseHeader('Content-Length');
461+
let contentLength = null;
462+
try { contentLength = xhr2.getResponseHeader('Content-Length'); } catch (e: any) {console.warn(`Failed to get Content-Length on request`);}
458463
if (contentLength && +contentLength > 1) {
459464
console.warn(
460465
`Range request for ${path} did not return a partial response: ${xhr2.status} "${xhr2.statusText}"`,

0 commit comments

Comments
 (0)