From 86e7015528bc479ca27a1f2395efce95502cd447 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Mon, 15 May 2023 17:10:18 -0400 Subject: [PATCH] Fix updater to follow redirects on latest --- updater/src/api.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/updater/src/api.rs b/updater/src/api.rs index 92f1723..2cf7306 100644 --- a/updater/src/api.rs +++ b/updater/src/api.rs @@ -103,8 +103,22 @@ impl AdoptiumAPI { .client .get_async(url) .await - .context("Failed to request release")? - .into_body(); + .context("Failed to request release")?; + // If we get a 301, respond to it + if response.status().as_u16() == 301 { + let location = response + .headers() + .get("location") + .context("Failed to get redirect location")? + .to_str() + .context("Failed to parse redirect location")?; + response = self + .client + .get_async(location) + .await + .context("Failed to request release")?; + } + let mut response = response.into_body(); let mut body = String::new(); response .read_to_string(&mut body) @@ -137,7 +151,7 @@ impl AdoptiumAPI { let latest: OutputRelease = self .latest(input_versions.most_recent_feature_version, arch, true) .await - .context("Failed to get version")? + .context("Failed to get version - latest")? .into(); let stable: OutputRelease = self .latest( @@ -146,7 +160,7 @@ impl AdoptiumAPI { true, ) .await - .context("Failed to get version")? + .context("Failed to get version - stable")? .into(); let lts: OutputRelease = self .latest( @@ -156,7 +170,7 @@ impl AdoptiumAPI { true, ) .await - .context("Failed to get version")? + .context("Failed to get version - lts")? .into(); Ok(OutputReleases { versions,