-
Notifications
You must be signed in to change notification settings - Fork 525
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
fetch url now show the final url after all redirect #2520
Comments
fetch will return the final redirect's url. If you can provide a minimal reproduction that doesn't use third party services I can look into it. test codeimport { once } from 'events'
import { createServer } from 'http'
const server = createServer((req, res) => {
if (req.url === '/redirect') {
res.writeHead(302, { Location: '/redirect2' })
res.end()
return
}
res.end('hello')
}).listen(0).unref()
await once(server, 'listening')
const r = await fetch(`http://localhost:${server.address().port}/redirect`)
console.log(r.url) // .../redirect2
server.close() |
OK, the minimal test is I want to get the final URL after all the redirect https://bit.ly/48b82fP the first redirect url will redirect to final url how to do that in nodejs builtin fetch aka undici.fetch to get the final url |
I'm sorry I can't help until there's a reproducible code example that doesn't use third party sites. Fetch by default will return the last redirect url. |
what reproducible code example you want? |
What does the spec say? What value should it have? |
Write the server needed to reproduce the behavior in Undici. |
added a test case for this issue which proves, that the final url is set to the response. |
in nodejs v21.2.0
await globalThis.fetch('https://bit.ly/48b82fP').then(_ => _.url) just show the first redirect url:
https://l.facebook.com/l.php?u=https://f.theloadedbaze.com/%3Ffbclid%3DIwAR09e4iW8r6DAGuJbtEfepgIwLKm1zsIcavDGWT7gbFqyX4E56N7fL9pQNQ&h=AT1dnnHhh3K5JfViDpurjF0I833b7Fs5ukXQIDMNju_dSkagEbhuGB1zjjrFKuOZF2k6IU9MSTTwz0FlSoW761RP7xoRXBay0mUmD5bJYggSXdVlLwb4vOVlNXcM3oRnYMlwr_sh4RQ
But in node-fetch:
import fetch from 'node-fetch'
await globalThis.fetch('https://bit.ly/48b82fP').then(_ => _.url) show the final redirect url:
https://www.facebook.com/flx/warn/?u=https%3A%2F%2Ff.theloadedbaze.com%2F%3Ffbclid%3DIwAR09e4iW8r6DAGuJbtEfepgIwLKm1zsIcavDGWT7gbFqyX4E56N7fL9pQNQ&h=AT3Lwqzvo-lauSwVjMfI9Q5fw0WWGVojnuGIDzB_6p8f_8TP-A4MTOdU8LcjH_2OZ6o8auwyrtzF_XZOwH9EQ9ZBb5KlZz4D_x6DoR58t-FSfF3bNDoXfC8iqpPm-mAp-8aqMYwuFOQ
I want to know how to get the final url after all redirect in undici fetch link that in node-fetch?
The text was updated successfully, but these errors were encountered: