From 8c442e742a40a41331ec354e9e44d7f6f58ce9d6 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Fri, 11 Apr 2025 14:02:06 -0300 Subject: [PATCH] fix: add range request support validation --- rust_rpc/src/main.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/rust_rpc/src/main.rs b/rust_rpc/src/main.rs index 11f05326..1908ce87 100644 --- a/rust_rpc/src/main.rs +++ b/rust_rpc/src/main.rs @@ -620,6 +620,28 @@ impl Downloader { async fn get_file_info(&self) -> Result<(u64, Option, String)> { let resp = self.client.head(&self.config.url).send().await?; + let accepts_ranges = resp + .headers() + .get("accept-ranges") + .and_then(|v| v.to_str().ok()) + .map(|v| v.contains("bytes")) + .unwrap_or(false); + + if !accepts_ranges { + let range_check = self + .client + .get(&self.config.url) + .header("Range", "bytes=0-0") + .send() + .await?; + + if range_check.status() != StatusCode::PARTIAL_CONTENT { + anyhow::bail!( + "Server does not support Range requests, cannot continue with parallel download" + ); + } + } + let file_size = if let Some(content_length) = resp.headers().get("content-length") { content_length.to_str()?.parse()? } else {