Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response.redirect with relative URLs #22

Open
lino-levan opened this issue Nov 14, 2023 · 3 comments
Open

Response.redirect with relative URLs #22

lino-levan opened this issue Nov 14, 2023 · 3 comments

Comments

@lino-levan
Copy link

This is sort of similar to #9 but I think it has some interesting semantics that might be worth looking into seperately.

The current spec is very clear that Response.redirect MUST be resolved against the current url. This is rather unfortunate by itself since server runtimes don't really have a concept of "current url". Outside of that, redirects (especially when paired with status code 307) are incredibly common for stuff like OAuth flows.

Currently, doing:

return Response.redirect("/home", 307);

just errors in Node and Deno (without the --location flag). The correct way to do this currently is

return new Response(null, {
    status: 307,
    headers: {
        "Location": "/home"
    }
});

which I think is suboptimal. Perhaps this issue should be raised upstream, because this could actually work in a web-standard Response.redirect. Ideally, Response.redirect would just use a relative location for status codes that support it. I'm hoping to champion this change in WinterCG and eventually land it upstream later.

@ljharb
Copy link
Member

ljharb commented Nov 14, 2023

Server runtimes can't have a concept of "current URL", which is why a number of parts of fetch can't be compliant outside a browser.

@lino-levan
Copy link
Author

Server runtimes can't have a concept of "current URL"

I mean, Deno has --location but I agree that this is one of the big issues with "spec-compliant" fetch on the server.

@KhafraDev
Copy link

Very late reply, sorry, but node (specifically undici) lets you set a global origin:

import { setGlobalOrigin } from 'undici'

setGlobalOrigin('http://what.ever')

Response.redirect('/home', 307)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants