js: Allow passing credentials option to fetch [#397] (#644)

* js: Allow passing credentials option to fetch [#397]
* fix passing custom headers in case where remote archive is < 16 kB
* clean up `any` usage
This commit is contained in:
Brandon Liu
2026-02-27 11:09:11 -05:00
committed by GitHub
parent 9ff3871133
commit c1014a5cf8
4 changed files with 80 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ import { mockServer } from "./utils";
import {
BufferPosition,
Entry,
FetchSource,
PMTiles,
RangeResponse,
SharedPromiseCache,
@@ -407,3 +408,36 @@ describe("pmtiles v3", () => {
});
});
});
describe("FetchSource", () => {
test("customHeaders are sent with requests", async () => {
mockServer.reset();
const source = new FetchSource(
"http://localhost:1337/example.pmtiles",
new Headers({ "X-Custom-Header": "test-value" }),
"include"
);
await source.getBytes(0, 100);
assert.strictEqual(
mockServer.lastRequestHeaders?.get("x-custom-header"),
"test-value"
);
assert.strictEqual(mockServer.lastCredentials, "include");
});
test("customHeaders are preserved on 416 retry", async () => {
mockServer.reset();
const source = new FetchSource(
"http://localhost:1337/small.pmtiles",
new Headers({ "X-Custom-Header": "retry-value" }),
"include"
);
await source.getBytes(0, 16384);
assert.strictEqual(mockServer.numRequests, 2);
assert.strictEqual(
mockServer.lastRequestHeaders?.get("x-custom-header"),
"retry-value",
"include"
);
});
});