Abort requests [#608] (#625)

* Properly abort requests using AbortController

* add basic adapter tests

---------

Co-authored-by: Andrew Dassonville <dassonville.andrew@gmail.com>
This commit is contained in:
Brandon Liu
2025-12-24 17:33:11 +08:00
committed by GitHub
parent a5f8a89256
commit cabe8a898a
6 changed files with 536 additions and 405 deletions

View File

@@ -215,12 +215,13 @@ export class Protocol {
}
if (this.metadata) {
return {
data: await instance.getTileJson(params.url),
};
const data = await instance.getTileJson(params.url);
abortController.signal.throwIfAborted();
return { data };
}
const h = await instance.getHeader();
abortController.signal.throwIfAborted();
if (h.minLon >= h.maxLon || h.minLat >= h.maxLat) {
console.error(
@@ -255,6 +256,7 @@ export class Protocol {
const header = await instance.getHeader();
const resp = await instance?.getZxy(+z, +x, +y, abortController.signal);
abortController.signal.throwIfAborted();
if (resp) {
return {
data: new Uint8Array(resp.data),

View File

@@ -355,7 +355,7 @@ export class FetchSource implements Source {
let userAgent = "";
if ("navigator" in globalThis) {
//biome-ignore lint: cf workers
userAgent = (globalThis as any).navigator.userAgent || "";
userAgent = (globalThis as any).navigator?.userAgent ?? "";
}
const isWindows = userAgent.indexOf("Windows") > -1;
const isChromiumBased = /Chrome|Chromium|Edg|OPR|Brave/.test(userAgent);