oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.55k stars 2.71k forks source link

The `fetch()` API ignores the `Request.redirect` property #10754

Open dahlia opened 5 months ago

dahlia commented 5 months ago

What version of Bun is running?

1.1.6

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

// redirect.ts
async function main() {
  const request = new Request("https://w3id.org/security/v1", {
    redirect: "manual",
  });
  const response = await fetch(request);
  console.log(response.url);
}

main();

[!NOTE] The URL https://w3id.org/security/v1 is just an example I found. It redirects to https://w3c-ccg.github.io/security-vocab/contexts/security-v1.jsonld.

What is the expected behavior?

$ node redirect.ts
https://w3id.org/security/v1
$ deno run --allow-net redirect.ts
https://w3id.org/security/v1

What do you see instead?

$ bun redirect.ts
https://w3c-ccg.github.io/security-vocab/contexts/security-v1.jsonld

Additional information

When you directly specify redirect: "manual" to fetch() (instead of a Request object), it apparently works correctly:

// redirect2.ts
async function main() {
  const response = await fetch("https://w3id.org/security/v1", {
    redirect: "manual",
  });
  console.log(response.url);
}

main();
$ bun redirect2.ts
https://w3id.org/security/v1
Jarred-Sumner commented 5 months ago

Confirming this is a bug