Fix updater to follow redirects on latest

This commit is contained in:
Nathan McCarty 2023-05-15 17:10:18 -04:00
parent 409fb0a41d
commit 86e7015528
Signed by: thatonelutenist
SSH Key Fingerprint: SHA256:hwQEcmak9E6sdU9bXc98RHw/Xd1AhpB5HZT7ZSVJkRM
1 changed files with 19 additions and 5 deletions

View File

@ -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,