Skip to content

Commit 40c91e9

Browse files
committed
Upgrade 'ureq' to 2.1 (from 1.5)
1 parent a5d5738 commit 40c91e9

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

onnxruntime-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ keywords = ["neuralnetworks", "onnx", "bindings"]
1818

1919
[build-dependencies]
2020
bindgen = { version = "0.55", optional = true }
21-
ureq = "1.5.1"
21+
ureq = "2.1"
2222

2323
# Used on Windows
2424
zip = "0.5"

onnxruntime-sys/build.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,9 @@ where
122122
P: AsRef<Path>,
123123
{
124124
let resp = ureq::get(source_url)
125-
.timeout_connect(1_000) // 1 second
126125
.timeout(std::time::Duration::from_secs(300))
127-
.call();
128-
129-
if resp.error() {
130-
panic!("ERROR: Failed to download {}: {:#?}", source_url, resp);
131-
}
126+
.call()
127+
.unwrap_or_else(|err| panic!("ERROR: Failed to download {}: {:?}", source_url, err));
132128

133129
let len = resp
134130
.header("Content-Length")

onnxruntime/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ thiserror = "1.0"
2727
tracing = "0.1"
2828

2929
# Enabled with 'model-fetching' feature
30-
ureq = { version = "1.5.1", optional = true }
30+
ureq = { version = "2.1", optional = true }
3131

3232
[dev-dependencies]
3333
image = "0.23"
3434
test-env-log = { version = "0.2", default-features = false, features = ["trace"] }
3535
tracing-subscriber = "0.2"
36-
ureq = "1.5.1"
36+
ureq = "2.1"
3737

3838
[features]
3939
# Fetch model from ONNX Model Zoo (https://github.com/onnx/models)

onnxruntime/src/download.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ impl AvailableOnnxModel {
7979
);
8080

8181
let resp = ureq::get(url)
82-
.timeout_connect(1_000) // 1 second
8382
.timeout(Duration::from_secs(180)) // 3 minutes
84-
.call();
83+
.call()
84+
.map_err(OrtDownloadError::UreqError)?;
8585

8686
assert!(resp.has("Content-Length"));
8787
let len = resp

onnxruntime/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ pub enum OrtDownloadError {
140140
/// Generic input/output error
141141
#[error("Error downloading data to file: {0}")]
142142
IoError(#[from] io::Error),
143+
#[cfg(feature = "model-fetching")]
144+
/// Download error by ureq
145+
#[error("Error downloading data to file: {0}")]
146+
UreqError(#[from] ureq::Error),
143147
/// Error getting content-length from an HTTP GET request
144148
#[error("Error getting content-length")]
145149
ContentLengthError,

onnxruntime/tests/integration_tests.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::{
55
time::Duration,
66
};
77

8+
use onnxruntime::error::OrtDownloadError;
9+
810
mod download {
911
use super::*;
1012

@@ -294,16 +296,15 @@ mod download {
294296
}
295297
}
296298

297-
fn get_imagenet_labels() -> Result<Vec<String>, io::Error> {
299+
fn get_imagenet_labels() -> Result<Vec<String>, OrtDownloadError> {
298300
// Download the ImageNet class labels, matching SqueezeNet's classes.
299301
let labels_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("synset.txt");
300302
if !labels_path.exists() {
301303
let url = "https://s3.amazonaws.com/onnx-model-zoo/synset.txt";
302304
println!("Downloading {:?} to {:?}...", url, labels_path);
303305
let resp = ureq::get(url)
304-
.timeout_connect(1_000) // 1 second
305306
.timeout(Duration::from_secs(180)) // 3 minutes
306-
.call();
307+
.call()?;
307308

308309
assert!(resp.has("Content-Length"));
309310
let len = resp
@@ -323,5 +324,7 @@ fn get_imagenet_labels() -> Result<Vec<String>, io::Error> {
323324
}
324325
let file = BufReader::new(fs::File::open(labels_path).unwrap());
325326

326-
file.lines().collect()
327+
file.lines()
328+
.map(|line| line.map_err(|io_err| OrtDownloadError::IoError(io_err)))
329+
.collect()
327330
}

0 commit comments

Comments
 (0)