summaryrefslogtreecommitdiff
path: root/cli/http_util.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-08-07 10:16:27 +0100
committerGitHub <noreply@github.com>2024-08-07 09:16:27 +0000
commitfe64cbd88ba0a2d9d6e3becb387b2bf6bc3afde8 (patch)
tree5a994f63bcd0dbb1562b5498af5e33618d0c6521 /cli/http_util.rs
parentd1b2a9822d499def513c5b178927c4e05c39caff (diff)
fix(upgrade): fallback to Content-Length header for progress bar (#24923)
If the "size hint" does not provide a value, fall back to using a "Content-Length" header.
Diffstat (limited to 'cli/http_util.rs')
-rw-r--r--cli/http_util.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/cli/http_util.rs b/cli/http_util.rs
index a8646c188..b47e91c70 100644
--- a/cli/http_util.rs
+++ b/cli/http_util.rs
@@ -23,6 +23,7 @@ use http::header::HeaderName;
use http::header::HeaderValue;
use http::header::ACCEPT;
use http::header::AUTHORIZATION;
+use http::header::CONTENT_LENGTH;
use http::header::IF_NONE_MATCH;
use http::header::LOCATION;
use http::StatusCode;
@@ -579,7 +580,15 @@ async fn get_response_body_with_progress(
) -> Result<Vec<u8>, AnyError> {
use http_body::Body as _;
if let Some(progress_guard) = progress_guard {
- if let Some(total_size) = response.body().size_hint().exact() {
+ let mut total_size = response.body().size_hint().exact();
+ if total_size.is_none() {
+ total_size = response
+ .headers()
+ .get(CONTENT_LENGTH)
+ .and_then(|val| val.to_str().ok())
+ .and_then(|s| s.parse::<u64>().ok());
+ }
+ if let Some(total_size) = total_size {
progress_guard.set_total_size(total_size);
let mut current_size = 0;
let mut data = Vec::with_capacity(total_size as usize);