Skip to content

Commit 638ed47

Browse files
author
Test User
committed
fix(deps): bump ureq to 3.3.0 and migrate downloader API
ureq 3.x moves timeout/config to Agent and uses http::Response for responses. Update perform_download to build an Agent with the request timeout, read Content-Length from headers(), and stream the body via Body::as_reader(). Closes #920
1 parent 5d5c675 commit 638ed47

3 files changed

Lines changed: 55 additions & 14 deletions

File tree

Cargo.lock

Lines changed: 37 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/terraphim_update/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ chrono = { workspace = true }
3030
semver = "1.0"
3131
sha2 = "0.11"
3232
hex = "0.4"
33-
ureq = "2.9"
33+
ureq = "3.3"
3434
dirs = "5.0"
3535
dialoguer = "0.12"
3636
# zipsign-api for signature verification (also pulled by self_update)

crates/terraphim_update/src/downloader.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! - Timeout handling
99
1010
use anyhow::{Result, anyhow};
11-
use std::io::{self, Write};
11+
use std::io::{self, Read, Write};
1212
use std::time::{Duration, Instant};
1313
use tracing::{debug, error, info, warn};
1414

@@ -204,24 +204,30 @@ fn perform_download(
204204
output_path: &std::path::Path,
205205
config: &DownloadConfig,
206206
) -> Result<u64> {
207-
let response = ureq::get(url)
208-
.timeout(config.timeout)
207+
let agent_config = ureq::Agent::config_builder()
208+
.timeout_global(Some(config.timeout))
209+
.http_status_as_error(false)
210+
.build();
211+
let agent = ureq::Agent::new_with_config(agent_config);
212+
213+
let response = agent
214+
.get(url)
209215
.call()
210216
.map_err(|e| anyhow!("HTTP request failed: {}", e))?;
211217

212-
if response.status() != 200 {
213-
return Err(anyhow!(
214-
"HTTP error: {} {}",
215-
response.status(),
216-
response.status_text()
217-
));
218+
let status = response.status();
219+
if status.as_u16() != 200 {
220+
return Err(anyhow!("HTTP error: {}", status));
218221
}
219222

220223
let content_length = response
221-
.header("Content-Length")
224+
.headers()
225+
.get("Content-Length")
226+
.and_then(|h| h.to_str().ok())
222227
.and_then(|h| h.parse::<u64>().ok());
223228

224-
let mut reader = response.into_reader();
229+
let mut body = response.into_body();
230+
let mut reader = body.as_reader();
225231

226232
let mut file = std::fs::File::create(output_path)?;
227233
let mut total_bytes = 0u64;

0 commit comments

Comments
 (0)