Skip to content

Commit 1629414

Browse files
authored
chore: update ureq (#1278)
1 parent 5fc4767 commit 1629414

File tree

9 files changed

+75
-43
lines changed

9 files changed

+75
-43
lines changed

Cargo.lock

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

sdk/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ tempfile = { version = "3.15", features = ["nightly"] }
204204

205205
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
206206
openssl = { version = "0.10.72", features = ["vendored"], optional = true }
207-
ureq = "2.4.0"
207+
ureq = "3.0.12"
208+
http = "1.3.1"
208209
url = "2.5.3"
209210

210211
[target.'cfg(any(target_os = "wasi", not(target_arch = "wasm32")))'.dependencies]

sdk/examples/v2show.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main() -> Result<()> {
3737
println!("Fetching remote manifest from {url}");
3838
let mut c2pa_data = Vec::new();
3939
let resp = ureq::get(&url).call()?;
40-
resp.into_reader().read_to_end(&mut c2pa_data)?;
40+
resp.into_body().into_reader().read_to_end(&mut c2pa_data)?;
4141
Reader::from_manifest_data_and_stream(&c2pa_data, &format, &mut file)
4242
}
4343
Err(Error::JumbfNotFound) => {

sdk/src/crypto/ocsp/fetch.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,21 @@ pub(crate) fn fetch_ocsp_response(certs: &[Vec<u8>]) -> Option<Vec<u8>> {
101101
// fetch OCSP response
102102
let request = ureq::get(req_url.as_str());
103103
let response = if let Some(host) = url.host() {
104-
request.set("Host", &host.to_string()).call().ok()? // for responders that don't support http 1.0
104+
request.header("Host", &host.to_string()).call().ok()? // for responders that don't support http 1.0
105105
} else {
106106
request.call().ok()?
107107
};
108108

109109
if response.status() == 200 {
110-
let len = response
111-
.header("Content-Length")
112-
.and_then(|s| s.parse::<usize>().ok())
110+
let body = response.into_body();
111+
let len = body
112+
.content_length()
113+
.and_then(|s| s.try_into().ok())
113114
.unwrap_or(10000);
114115

115116
let mut ocsp_rsp: Vec<u8> = Vec::with_capacity(len);
116117

117-
response
118-
.into_reader()
118+
body.into_reader()
119119
.take(1000000)
120120
.read_to_end(&mut ocsp_rsp)
121121
.ok()?;

sdk/src/crypto/time_stamp/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ pub enum TimeStampError {
5353
NonceMismatch,
5454

5555
/// The time stamp service responded with an error condition.
56-
#[error("service responded with an HTTP error (status = {0}, content-type = {1})")]
57-
HttpErrorResponse(u16, String),
56+
#[error("service responded with an HTTP error (status = {0}, content-type = {1:?})")]
57+
HttpErrorResponse(u16, Option<String>),
5858

5959
/// Unable to complete the HTTPS time stamp request.
6060
///

sdk/src/crypto/time_stamp/http_request.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use async_generic::async_generic;
1515
use bcder::{decode::Constructed, encode::Values};
16+
use http::header;
1617

1718
use crate::{
1819
crypto::{
@@ -85,24 +86,27 @@ fn time_stamp_request_http(
8586

8687
if let Some(headers) = headers {
8788
for (ref name, ref value) in headers {
88-
req = req.set(name.as_str(), value.as_str());
89+
req = req.header(name.as_str(), value.as_str());
8990
}
9091
}
9192

9293
let response = req
93-
.set("Content-Type", HTTP_CONTENT_TYPE_REQUEST)
94-
.send_bytes(&body)?;
95-
96-
if response.status() == 200 && response.content_type() == HTTP_CONTENT_TYPE_RESPONSE {
97-
let len = response
98-
.header("Content-Length")
99-
.and_then(|s| s.parse::<usize>().ok())
94+
.header(header::CONTENT_TYPE, HTTP_CONTENT_TYPE_REQUEST)
95+
.send(&body)?;
96+
97+
let content_type = response
98+
.headers()
99+
.get(header::CONTENT_TYPE)
100+
.and_then(|header| header.to_str().ok());
101+
if response.status() == 200 && content_type == Some(HTTP_CONTENT_TYPE_RESPONSE) {
102+
let body = response.into_body();
103+
let len = body
104+
.content_length()
105+
.and_then(|content_length| content_length.try_into().ok())
100106
.unwrap_or(20000);
101-
102107
let mut response_bytes: Vec<u8> = Vec::with_capacity(len);
103108

104-
response
105-
.into_reader()
109+
body.into_reader()
106110
.take(1000000)
107111
.read_to_end(&mut response_bytes)?;
108112

@@ -125,8 +129,8 @@ fn time_stamp_request_http(
125129
Ok(response_bytes)
126130
} else {
127131
Err(TimeStampError::HttpErrorResponse(
128-
response.status(),
129-
response.content_type().to_string(),
132+
response.status().as_u16(),
133+
content_type.map(|content_type| content_type.to_owned()),
130134
))
131135
}
132136
}

sdk/src/settings/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ impl Settings {
324324
let toml = ureq::get(url)
325325
.call()
326326
.map_err(|_| Error::FailedToFetchSettings)?
327-
.into_string()?;
327+
.into_body()
328+
.read_to_string()
329+
.map_err(|_| Error::FailedToFetchSettings)?;
328330
Settings::from_toml(&toml)
329331
}
330332

sdk/src/settings/signer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ impl Signer for RemoteSigner {
123123
use std::io::Read;
124124

125125
let response = ureq::post(&self.url)
126-
.send_bytes(data)
126+
.send(data)
127127
.map_err(|_| Error::FailedToRemoteSign)?;
128128
let mut bytes: Vec<u8> = Vec::with_capacity(self.reserve_size);
129129
response
130+
.into_body()
130131
.into_reader()
131132
.take(self.reserve_size as u64)
132133
.read_to_end(&mut bytes)?;

sdk/src/store.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3711,26 +3711,25 @@ impl Store {
37113711
#[cfg(all(feature = "fetch_remote_manifests", not(target_os = "wasi")))]
37123712
fn fetch_remote_manifest(url: &str) -> Result<Vec<u8>> {
37133713
use conv::ValueFrom;
3714-
use ureq::Error as uError;
37153714

37163715
//const MANIFEST_CONTENT_TYPE: &str = "application/x-c2pa-manifest-store"; // todo verify once these are served
37173716
const DEFAULT_MANIFEST_RESPONSE_SIZE: usize = 10 * 1024 * 1024; // 10 MB
37183717

37193718
match ureq::get(url).call() {
37203719
Ok(response) => {
37213720
if response.status() == 200 {
3722-
let len = response
3723-
.header("Content-Length")
3724-
.and_then(|s| s.parse::<usize>().ok())
3721+
let body = response.into_body();
3722+
let len = body
3723+
.content_length()
3724+
.and_then(|content_length| content_length.try_into().ok())
37253725
.unwrap_or(DEFAULT_MANIFEST_RESPONSE_SIZE); // todo figure out good max to accept
37263726

37273727
let mut response_bytes: Vec<u8> = Vec::with_capacity(len);
37283728

37293729
let len64 = u64::value_from(len)
37303730
.map_err(|_err| Error::BadParam("value out of range".to_string()))?;
37313731

3732-
response
3733-
.into_reader()
3732+
body.into_reader()
37343733
.take(len64)
37353734
.read_to_end(&mut response_bytes)
37363735
.map_err(|_err| {
@@ -3741,17 +3740,12 @@ impl Store {
37413740
} else {
37423741
Err(Error::RemoteManifestFetch(format!(
37433742
"fetch failed: code: {}, status: {}",
3744-
response.status(),
3745-
response.status_text()
3743+
response.status().as_u16(),
3744+
response.status().as_str()
37463745
)))
37473746
}
37483747
}
3749-
Err(uError::Status(code, resp)) => Err(Error::RemoteManifestFetch(format!(
3750-
"code: {}, response: {}",
3751-
code,
3752-
resp.status_text()
3753-
))),
3754-
Err(uError::Transport(_)) => Err(Error::RemoteManifestFetch(url.to_string())),
3748+
Err(err) => Err(Error::RemoteManifestFetch(err.to_string())),
37553749
}
37563750
}
37573751

0 commit comments

Comments
 (0)