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

🐛 Bug Report — Runtime APIs: Get an incorrect Location param when using Response.redirect #5221

Open
h11g opened this issue Mar 11, 2024 · 2 comments

Comments

@h11g
Copy link

h11g commented Mar 11, 2024

When I use wrangler dev --host localhost:3343 for local development, I want to get a redirect response. But my port number was mishandled and I can’t get the redirect address I’m hoping for. I'm sure it's not the browser's behavior.

wrangler version: ^3.32.0

Example

image

@h11g h11g changed the title 🐛 Bug Report — Get an incorrect Location param when using Response.redirect 🐛 Bug Report — Runtime API: Get an incorrect Location param when using Response.redirect Mar 11, 2024
@h11g h11g changed the title 🐛 Bug Report — Runtime API: Get an incorrect Location param when using Response.redirect 🐛 Bug Report — Runtime APIs: Get an incorrect Location param when using Response.redirect Mar 11, 2024
@mrbbot
Copy link
Contributor

mrbbot commented Mar 11, 2024

Hey! 👋 Thanks for raising this. I'm able to reproduce it locally. This is very likely an issue with wrangler/miniflare so I'm going to transfer this to the workers-sdk repo. 👍

@mrbbot mrbbot transferred this issue from cloudflare/workerd Mar 11, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Mar 11, 2024
@mrbbot mrbbot moved this from Untriaged to Backlog in workers-sdk Mar 11, 2024
@jfnault-seedbox
Copy link

Im experimenting the same issue

From what I found, seem to have been introduced in
#4950

packages/wrangler/templates/startDevWorker/ProxyWorker.ts
function rewriteUrlRelatedHeaders(headers: Headers, from: URL, to: URL) { headers.forEach((value, key) => { if (typeof value === "string" && value.includes(from.host)) { headers.set( key, value.replaceAll(from.origin, to.origin).replaceAll(from.host, to.host) ); } }); }

I start the worker like this:
npx wrangler dev --env dev --assets assets --host devsite.localg --local-upstream devsite.localg:33667

devsite.localg:33667: is my origin, a node express server

--host devsite.localg: I access my worker from same domain devsite.localg:8787

Behavior:
Url: devsite.localg:8787/to-redirect

with the script above is converted to:
http://devsite.localg:8787:8787:8787/destination

this is because of:
value.replaceAll(from.origin, to.origin).replaceAll(from.host, to.host)

there is the value I have for (from , to)

{
'from.origin': 'http://devsite.localg',
'to.origin': 'devsite.localg:8787',
'from.host': 'devsite.localg',
'to.host': 'devsite.localg:8787'
}

"http://devsite.localg:8787/destination"
.replaceAll("devsite.localg", "devsite.localg:8787")
.replaceAll("devsite.localg", "devsite.localg:8787")

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

No branches or pull requests

4 participants