summaryrefslogtreecommitdiff
path: root/test_util/src/lib.rs
diff options
context:
space:
mode:
authorKamil Ogórek <kamil.ogorek@gmail.com>2023-02-10 16:11:11 +0100
committerGitHub <noreply@github.com>2023-02-10 10:11:11 -0500
commit5778e1196e5adbae77e5a05bd7cfb4879b012739 (patch)
treec382aec5bf41584b81f0696834f1b0261dabebda /test_util/src/lib.rs
parent4baaa246a256a82e725ddf07015bad72ec13f3e5 (diff)
feat(install): follow redirects for urls with no path (#17449)
This change makes absolute urls, that contain no path like `deno install https://my-cli.io` to follow redirects and extract the name from it. It allows modifies `test_util` server listener on port `4550` (`REDIRECT_ABSOLUTE_PORT`) to allow for specifying `redirect_to` query param, that fill use that value for it's next redirect. Fixes https://github.com/denoland/deno/issues/17409
Diffstat (limited to 'test_util/src/lib.rs')
-rw-r--r--test_util/src/lib.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs
index 45008cf1f..2f85ca1b6 100644
--- a/test_util/src/lib.rs
+++ b/test_util/src/lib.rs
@@ -594,6 +594,28 @@ async fn absolute_redirect(
) -> hyper::Result<Response<Body>> {
let path = req.uri().path();
+ if path == "/" {
+ // We have to manually extract query params here,
+ // as `req.uri()` returns `PathAndQuery` only,
+ // and we cannot use `Url::parse(req.uri()).query_pairs()`,
+ // as it requires url to have a proper base.
+ let query_params: HashMap<_, _> = req
+ .uri()
+ .query()
+ .unwrap_or_default()
+ .split('&')
+ .filter_map(|s| {
+ s.split_once('=').map(|t| (t.0.to_owned(), t.1.to_owned()))
+ })
+ .collect();
+
+ if let Some(url) = query_params.get("redirect_to") {
+ println!("URL: {url:?}");
+ let redirect = redirect_resp(url.to_owned());
+ return Ok(redirect);
+ }
+ }
+
if path.starts_with("/REDIRECT") {
let url = &req.uri().path()[9..];
println!("URL: {url:?}");