From fe64cbd88ba0a2d9d6e3becb387b2bf6bc3afde8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 7 Aug 2024 10:16:27 +0100 Subject: 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. --- cli/http_util.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'cli/http_util.rs') 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, 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::().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); -- cgit v1.2.3