diff options
author | Luca Casonato <lucacasonato@yahoo.com> | 2021-01-18 13:59:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-18 13:59:29 +0100 |
commit | 7a30d1a3d85b47434c1bdbd03052ade3dba3c77c (patch) | |
tree | 34df25c43fd690c7acd62d9a8c72704553eb80ae | |
parent | 12577f2d9a08256417af2f1e92ed7f667f7a4a6a (diff) |
fix: redirect in --location relative fetch (#9150)
-rw-r--r-- | cli/tests/081_location_relative_fetch_redirect.ts | 2 | ||||
-rw-r--r-- | cli/tests/081_location_relative_fetch_redirect.ts.out | 1 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 6 | ||||
-rw-r--r-- | op_crates/fetch/26_fetch.js | 4 | ||||
-rw-r--r-- | op_crates/fetch/lib.rs | 2 |
5 files changed, 13 insertions, 2 deletions
diff --git a/cli/tests/081_location_relative_fetch_redirect.ts b/cli/tests/081_location_relative_fetch_redirect.ts new file mode 100644 index 000000000..742ef0afb --- /dev/null +++ b/cli/tests/081_location_relative_fetch_redirect.ts @@ -0,0 +1,2 @@ +const response = await fetch("/"); +console.log(response.url); diff --git a/cli/tests/081_location_relative_fetch_redirect.ts.out b/cli/tests/081_location_relative_fetch_redirect.ts.out new file mode 100644 index 000000000..f62b93195 --- /dev/null +++ b/cli/tests/081_location_relative_fetch_redirect.ts.out @@ -0,0 +1 @@ +[WILDCARD]http://localhost:4545/ diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 226bf9b9b..9cb5cd5f1 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -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", diff --git a/op_crates/fetch/26_fetch.js b/op_crates/fetch/26_fetch.js index c8a470033..52c281d3b 100644 --- a/op_crates/fetch/26_fetch.js +++ b/op_crates/fetch/26_fetch.js @@ -1373,7 +1373,7 @@ redirected, rid: fetchResponse.bodyRid, status: fetchResponse.status, - url, + url: fetchResponse.url, }); const response = new Response(responseBody, responseInit); @@ -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; diff --git a/op_crates/fetch/lib.rs b/op_crates/fetch/lib.rs index f882736f5..256e7904d 100644 --- a/op_crates/fetch/lib.rs +++ b/op_crates/fetch/lib.rs @@ -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(); @@ -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, })) } |