Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 92f7faa

Browse files
committed
Remove opaqueredirect Response handling, ref #177
`undici` no longer returns `opaqueredirect` `Response`s when `redirect` is set to `manual` as of nodejs/undici#1210.
1 parent 0fd23dc commit 92f7faa

File tree

2 files changed

+6
-25
lines changed

2 files changed

+6
-25
lines changed

packages/core/src/standards/http.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -823,32 +823,11 @@ export async function fetch(
823823
}
824824

825825
// Convert the response to our hybrid Response
826-
let res: Response;
827-
if (baseRes.type === "opaqueredirect") {
828-
// Unpack opaque responses. This restriction isn't needed server-side,
829-
// and Cloudflare doesn't support Response types anyway.
830-
// @ts-expect-error symbol properties are not included in type definitions
831-
const internalResponse = baseRes[fetchSymbols.kState].internalResponse;
832-
const headersList = internalResponse.headersList;
833-
assert(headersList.length % 2 === 0);
834-
const headers = new Headers();
835-
for (let i = 0; i < headersList.length; i += 2) {
836-
headers.append(headersList[i], headersList[i + 1]);
837-
}
838-
// Cloudflare returns a body here, but undici aborts the stream so
839-
// unfortunately it's unusable :(
840-
res = new Response(null, {
841-
status: internalResponse.status,
842-
statusText: internalResponse.statusText,
843-
headers,
844-
});
845-
} else {
826+
const res = new Response(
846827
// https://fetch.spec.whatwg.org/#null-body-status
847-
res = new Response(
848-
nullBodyStatus.includes(baseRes.status) ? null : baseRes.body,
849-
baseRes
850-
);
851-
}
828+
nullBodyStatus.includes(baseRes.status) ? null : baseRes.body,
829+
baseRes
830+
);
852831
// @ts-expect-error internal kGuard isn't included in type definitions
853832
res.headers[fetchSymbols.kGuard] = "immutable";
854833

packages/core/test/standards/http.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,8 @@ test('fetch: returns full Response for "manual" redirect', async (t) => {
10361036
t.is(res.statusText, "Found");
10371037
t.is(res.headers.get("Location"), `/?n=2`);
10381038
t.is(res.headers.get("Set-Cookie"), "n=3");
1039+
// https://github.com/cloudflare/miniflare/issues/177
1040+
t.is(res.url, url.href);
10391041
});
10401042
test("fetch: waits for input gate to open before returning", async (t) => {
10411043
const upstream = (await useServer(t, (req, res) => res.end("upstream"))).http;

0 commit comments

Comments
 (0)