Skip to content

Fetch: Allow manual redirect handling #1193

Closed

Description

@adamburgess

This would solve...

Currently you only get an opaque responses using fetch(..., { redirect: 'manual' }), for example:

import { fetch } from 'undici'
fetch('https://httpbin.org/status/302', {redirect: 'manual'})
      .then(res => console.log(res.status, res.headers))
// -> 0 HeadersList(0) []

This is what the spec says should happen, but it is not very useful for a server-side library...

The implementation should look like...

redirect: 'manual' should allow me to get the 302 request and read it like normal.

Additional context

Deno changed their fetch API to support this: denoland/deno#8353 denoland/deno#4389

fetch('https://httpbin.org/status/302', {redirect: 'manual'})
      .then(res => console.log(res.status, res.headers))
/* -> 302 Headers {
        "access-control-allow-credentials": "true",
        "access-control-allow-origin": "*",
        "content-length": "0",
        date: "Tue, 01 Feb 2022 13:51:40 GMT",
        location: "/redirect/1",
        server: "gunicorn/19.9.0"
      }
*/

Cloudflare Workers' fetch API also supports this.

Activity

  1. added
    enhancement
    on Feb 1, 2022
  2. changed the title [-]Fetch: Allow manual redirects[/-] [+]Fetch: Allow manual redirect handling[/+] on Feb 1, 2022
  3. adamburgess commented on Feb 1, 2022

    @adamburgess
    Author

    nodejs/node#41749 (comment) claims it will be added, so I'll close this for now.
    Feel free to reopen if you'd like this issue to track support for it here :)

  4. benjamingr commented on Feb 1, 2022

    @benjamingr
    Member

    I think it's worth keeping an issue open to make sure this doesn't get missed :]

    (If you feel strongly the issue should stay closed let me know and I'll re-close it and open a new one)

  5. mcollina commented on Feb 2, 2022

    @mcollina
    SponsorMember

    Would you like to send a Pull Request to address this issue? Remember to add unit tests.

  6. RaisinTen commented on Feb 7, 2022

    @RaisinTen
    Member

    Sent a PR to implement this - #1210

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions