Worker is lowercasing URL using Response.redirect

Using this code:
async function redirect(request) {
const uri = request.url.replace(/^https:\/\/.*?\//gi, "/");
console.log(uri);
let url = "https://mirrors.lifehacker101.net/flashcard-archive/" + uri;
console.log(url);

return Response.redirect(url);
}
async function redirect(request) {
const uri = request.url.replace(/^https:\/\/.*?\//gi, "/");
console.log(uri);
let url = "https://mirrors.lifehacker101.net/flashcard-archive/" + uri;
console.log(url);

return Response.redirect(url);
}
it correctly logs:
/TEST.zip
https://mirrors.lifehacker101.net/flashcard-archive//TEST.zip
/TEST.zip
https://mirrors.lifehacker101.net/flashcard-archive//TEST.zip
However it is doing this instead:
alt-svc: h3=":443"; ma=86400
cf-ray: 8b95d70761e72d54-yvr
connection: keep-alive
content-length: 0
date: mon, 26 aug 2024 18:21:09 gmt
location: https://mirrors.lifehacker101.net/flashcard-archive//test.zip
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=f6ywic6ivn7gxmcc5of0ttz8mshxbgs3x1uxhauebsfxf8pjmihymutle5mil4jijka6g1lz0g9%2fzrm8fk2phzsnmbin3onytxadmywve7vreftyi07xfrair4y8bcv1ande8qvoqlulvu8ai0mmt%2ft8zmc5eryp7ci5lw550doptvwkumzwml%2fwfb9g"}],"group":"cf-nel","max_age":604800}
server: cloudflare
vary: accept-encoding
alt-svc: h3=":443"; ma=86400
cf-ray: 8b95d70761e72d54-yvr
connection: keep-alive
content-length: 0
date: mon, 26 aug 2024 18:21:09 gmt
location: https://mirrors.lifehacker101.net/flashcard-archive//test.zip
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=f6ywic6ivn7gxmcc5of0ttz8mshxbgs3x1uxhauebsfxf8pjmihymutle5mil4jijka6g1lz0g9%2fzrm8fk2phzsnmbin3onytxadmywve7vreftyi07xfrair4y8bcv1ande8qvoqlulvu8ai0mmt%2ft8zmc5eryp7ci5lw550doptvwkumzwml%2fwfb9g"}],"group":"cf-nel","max_age":604800}
server: cloudflare
vary: accept-encoding
This causes 404 on the target location's web server. Is there something going on that I don't know about causing this?
2 Replies
lifehackerhansol
lifehackerhansolOP4mo ago
scratch that. it seems to be a false alarm. It only happens in the preview UI that said, it would be appreciated if the preview interface didn't differ so much in behaviour from a simple curl...
Walshy
Walshy4mo ago
Quick edit is best effort, we recommend developing locally with Wrangler + workerd (the Workers runtime) -- this gives a much much more accurate use
Want results from more Discord servers?
Add your server