Unverified Commit 658fb778 authored by Hong Minhee's avatar Hong Minhee
Browse files

Merge pull request #324 from allouis/handle-redirects

parents d0145238 0b7ecec8
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -8,6 +8,10 @@ Version 1.6.7

To be released.

 -  Fixed `doubleKnock()` to properly handle redirects with path-only `Location`
    headers by resolving them relative to the original request URL.
    [[#324] by Fabien O'Carroll]


Version 1.6.6
-------------
@@ -20,6 +24,7 @@ Released on July 15, 2025.

[#294]: https://github.com/fedify-dev/fedify/issues/294
[#295]: https://github.com/fedify-dev/fedify/pull/295
[#324]: https://github.com/fedify-dev/fedify/pull/324


Version 1.6.5
+40 −0
Original line number Diff line number Diff line
@@ -1935,3 +1935,43 @@ test("doubleKnock() regression test for TypeError: unusable bug #294", async ()

  fetchMock.hardReset();
});

test("doubleKnock() regression test for redirect handling bug", async () => {
  // This test reproduces the bug where the redirect handling in doubleKnock
  // would throw for a path only Location header

  fetchMock.spyGlobal();

  fetchMock.post("https://example.com/inbox-retry-redirect", (_cl) => {
    return new Response(null, {
      status: 302,
      headers: {
        location: "/final-destination",
      },
    });
  });

  fetchMock.post("https://example.com/final-destination", () => {
    return new Response("Success", { status: 200 });
  });

  const request = new Request("https://example.com/inbox-retry-redirect", {
    method: "POST",
    body: "Test activity content",
    headers: {
      "Content-Type": "application/activity+json",
    },
  });

  const response = await doubleKnock(
    request,
    {
      keyId: rsaPublicKey2.id!,
      privateKey: rsaPrivateKey2,
    },
  );

  assertEquals(response.status, 200);

  fetchMock.hardReset();
});
+2 −1
Original line number Diff line number Diff line
@@ -1233,7 +1233,8 @@ function createRedirectRequest(
  location: string,
  body: ArrayBuffer | undefined,
): Request {
  return new Request(location, {
  const url = new URL(location, request.url);
  return new Request(url, {
    method: request.method,
    headers: request.headers,
    body,