mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
fix: redirect in --location relative fetch (#9150)
This commit is contained in:
parent
12577f2d9a
commit
7a30d1a3d8
5 changed files with 13 additions and 2 deletions
2
cli/tests/081_location_relative_fetch_redirect.ts
Normal file
2
cli/tests/081_location_relative_fetch_redirect.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
const response = await fetch("/");
|
||||||
|
console.log(response.url);
|
1
cli/tests/081_location_relative_fetch_redirect.ts.out
Normal file
1
cli/tests/081_location_relative_fetch_redirect.ts.out
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[WILDCARD]http://localhost:4545/
|
|
@ -2662,6 +2662,12 @@ itest!(_080_deno_emit_permissions {
|
||||||
exit_code: 1,
|
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 {
|
itest!(js_import_detect {
|
||||||
args: "run --quiet --reload js_import_detect.ts",
|
args: "run --quiet --reload js_import_detect.ts",
|
||||||
output: "js_import_detect.ts.out",
|
output: "js_import_detect.ts.out",
|
||||||
|
|
|
@ -1373,7 +1373,7 @@
|
||||||
redirected,
|
redirected,
|
||||||
rid: fetchResponse.bodyRid,
|
rid: fetchResponse.bodyRid,
|
||||||
status: fetchResponse.status,
|
status: fetchResponse.status,
|
||||||
url,
|
url: fetchResponse.url,
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = new Response(responseBody, responseInit);
|
const response = new Response(responseBody, responseInit);
|
||||||
|
@ -1404,7 +1404,7 @@
|
||||||
!redirectUrl.startsWith("http://") &&
|
!redirectUrl.startsWith("http://") &&
|
||||||
!redirectUrl.startsWith("https://")
|
!redirectUrl.startsWith("https://")
|
||||||
) {
|
) {
|
||||||
redirectUrl = new URL(redirectUrl, url).href;
|
redirectUrl = new URL(redirectUrl, fetchResponse.url).href;
|
||||||
}
|
}
|
||||||
url = redirectUrl;
|
url = redirectUrl;
|
||||||
redirected = true;
|
redirected = true;
|
||||||
|
|
|
@ -227,6 +227,7 @@ pub async fn op_fetch_send(
|
||||||
|
|
||||||
//debug!("Fetch response {}", url);
|
//debug!("Fetch response {}", url);
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
|
let url = res.url().to_string();
|
||||||
let mut res_headers = Vec::new();
|
let mut res_headers = Vec::new();
|
||||||
for (key, val) in res.headers().iter() {
|
for (key, val) in res.headers().iter() {
|
||||||
let key_string = key.to_string();
|
let key_string = key.to_string();
|
||||||
|
@ -261,6 +262,7 @@ pub async fn op_fetch_send(
|
||||||
"status": status.as_u16(),
|
"status": status.as_u16(),
|
||||||
"statusText": status.canonical_reason().unwrap_or(""),
|
"statusText": status.canonical_reason().unwrap_or(""),
|
||||||
"headers": res_headers,
|
"headers": res_headers,
|
||||||
|
"url": url,
|
||||||
"responseRid": rid,
|
"responseRid": rid,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue