Skip to content

Commit

Permalink
Check the HTTP status code when downloading source files
Browse files Browse the repository at this point in the history
We especially don't want to download the HTML response as source
file/archive when the download fails due to HTTP 404 Not Found.
Successful downloads should only result in OK (200) but we could relax
the check via `response.status()..is_success()` (checks if status is
within 200-299) if necessary (if some HTTP servers send wrong/weird
status codes).

Signed-off-by: Michael Weiss <michael.weiss@atos.net>
  • Loading branch information
primeos-work committed Oct 11, 2023
1 parent b76e4d3 commit 1cf3d90
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/commands/source/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ async fn perform_download(
Err(e) => return Err(e).with_context(|| anyhow!("Downloading '{}'", &source.url())),
};

if response.status() != reqwest::StatusCode::OK {
return Err(anyhow!(
"Received HTTP status code \"{}\" but \"{}\" is expected for a successful download",
response.status(),
reqwest::StatusCode::OK
))
.with_context(|| anyhow!("Downloading \"{}\" failed", &source.url()));
}

progress
.lock()
.await
Expand Down

0 comments on commit 1cf3d90

Please sign in to comment.