Commit 886084a0 authored by r-4bb1t's avatar r-4bb1t
Browse files

feat: enhance document loading with AbortSignal support in getDocumentLoader and lookupObject

parent 3eae285a
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -330,6 +330,9 @@ export function getDocumentLoader(
    url: string,
    _options?: DocumentLoaderOptions,
  ): Promise<RemoteDocument> {
    if (_options?.signal?.aborted) {
      throw new DOMException("Aborted", "AbortError");
    }
    if (!skipPreloadedContexts && url in preloadedContexts) {
      logger.debug("Using preloaded context: {url}.", { url });
      return {
@@ -355,13 +358,14 @@ export function getDocumentLoader(
      // to work around it we specify `redirect: "manual"` here too:
      // https://github.com/oven-sh/bun/issues/10754
      redirect: "manual",
      signal: _options?.signal,
    });
    // Follow redirects manually to get the final URL:
    if (
      response.status >= 300 && response.status < 400 &&
      response.headers.has("Location")
    ) {
      return load(response.headers.get("Location")!);
      return load(response.headers.get("Location")!, _options);
    }
    return getRemoteDocument(url, response, load);
  }
+6 −2
Original line number Diff line number Diff line
@@ -139,7 +139,9 @@ async function lookupObjectInternal(
  let document: unknown | null = null;
  if (identifier.protocol === "http:" || identifier.protocol === "https:") {
    try {
      const remoteDoc = await documentLoader(identifier.href);
      const remoteDoc = await documentLoader(identifier.href, {
        signal: options.signal,
      });
      document = remoteDoc.document;
    } catch (error) {
      logger.debug("Failed to fetch remote document:\n{error}", { error });
@@ -162,7 +164,9 @@ async function lookupObjectInternal(
          ) || l.rel !== "self"
      ) continue;
      try {
        const remoteDoc = await documentLoader(l.href);
        const remoteDoc = await documentLoader(l.href, {
          signal: options.signal,
        });
        document = remoteDoc.document;
        break;
      } catch (error) {