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

feat: integrate AbortSignal into `DoubleKnockOptions` for request cancellation

parent a4ade8ce
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ export function getAuthenticatedDocumentLoader(
  validateCryptoKey(identity.privateKey);
  async function load(
    url: string,
    _options?: DocumentLoaderOptions,
    options?: DocumentLoaderOptions,
  ): Promise<RemoteDocument> {
    if (!allowPrivateAddress) {
      try {
@@ -77,7 +77,12 @@ export function getAuthenticatedDocumentLoader(
    const response = await doubleKnock(
      originalRequest,
      identity,
      { specDeterminer, log: logRequest, tracerProvider },
      {
        specDeterminer,
        log: logRequest,
        tracerProvider,
        signal: options?.signal,
      },
    );
    return getRemoteDocument(url, response, load);
  }
+8 −1
Original line number Diff line number Diff line
@@ -1237,6 +1237,11 @@ export interface DoubleKnockOptions {
   * is used.
   */
  tracerProvider?: TracerProvider;

  /**
   * An `AbortSignal` for cancellation.
   */
  signal?: AbortSignal;
}

/**
@@ -1283,7 +1288,7 @@ export async function doubleKnock(
  identity: { keyId: URL; privateKey: CryptoKey },
  options: DoubleKnockOptions = {},
): Promise<Response> {
  const { specDeterminer, log, tracerProvider } = options;
  const { specDeterminer, log, tracerProvider, signal } = options;
  const origin = new URL(request.url).origin;
  const firstTrySpec: HttpMessageSignaturesSpec = specDeterminer == null
    ? "rfc9421"
@@ -1308,6 +1313,7 @@ export async function doubleKnock(
    // to work around it we specify `redirect: "manual"` here too:
    // https://github.com/oven-sh/bun/issues/10754
    redirect: "manual",
    signal,
  });
  // Follow redirects manually to get the final URL:
  if (
@@ -1355,6 +1361,7 @@ export async function doubleKnock(
      // to work around it we specify `redirect: "manual"` here too:
      // https://github.com/oven-sh/bun/issues/10754
      redirect: "manual",
      signal,
    });
    // Follow redirects manually to get the final URL:
    if (