From 5778e1196e5adbae77e5a05bd7cfb4879b012739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Fri, 10 Feb 2023 16:11:11 +0100 Subject: 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 --- test_util/src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test_util/src') 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> { 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:?}"); -- cgit v1.2.3