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

fix: redirect in --location relative fetch #9150

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/tests/081_location_relative_fetch_redirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const response = await fetch("/");
console.log(response.url);
1 change: 1 addition & 0 deletions cli/tests/081_location_relative_fetch_redirect.ts.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[WILDCARD]http://localhost:4545/
6 changes: 6 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2662,6 +2662,12 @@ itest!(_080_deno_emit_permissions {
exit_code: 1,
});

itest!(_081_location_relative_fetch_redirect {
args: "run --location http://127.0.0.1:4546/ --allow-net 081_location_relative_fetch_redirect.ts",
output: "081_location_relative_fetch_redirect.ts.out",
http_server: true,
});

itest!(js_import_detect {
args: "run --quiet --reload js_import_detect.ts",
output: "js_import_detect.ts.out",
Expand Down
4 changes: 2 additions & 2 deletions op_crates/fetch/26_fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@
redirected,
rid: fetchResponse.bodyRid,
status: fetchResponse.status,
url,
url: fetchResponse.url,
});

const response = new Response(responseBody, responseInit);
Expand Down Expand Up @@ -1404,7 +1404,7 @@
!redirectUrl.startsWith("http://") &&
!redirectUrl.startsWith("https://")
) {
redirectUrl = new URL(redirectUrl, url).href;
redirectUrl = new URL(redirectUrl, fetchResponse.url).href;
}
url = redirectUrl;
redirected = true;
Expand Down
2 changes: 2 additions & 0 deletions op_crates/fetch/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ pub async fn op_fetch_send(

//debug!("Fetch response {}", url);
let status = res.status();
let url = res.url().to_string();
let mut res_headers = Vec::new();
for (key, val) in res.headers().iter() {
let key_string = key.to_string();
Expand Down Expand Up @@ -261,6 +262,7 @@ pub async fn op_fetch_send(
"status": status.as_u16(),
"statusText": status.canonical_reason().unwrap_or(""),
"headers": res_headers,
"url": url,
"responseRid": rid,
}))
}
Expand Down