Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ureq example to version 3 of the ureq crate. #186

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bytesize = "1.2.0"
cap = { version = "0.1.2", features = ["stats"] }
is_ci = "1.1.1"
tempfile = "3.5.0"
ureq = { version = "2.8.0", features = ["http-crate"] }
ureq = "3.0"
reqwest = { version = "0.12", features = ["blocking", "gzip"] }
serial_test = "3.1.1"
parking_lot = "0.12.1"
Expand Down
15 changes: 7 additions & 8 deletions examples/list_recent_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,15 @@ fn names(name: &str) -> Result<impl Iterator<Item = String>, Box<dyn Error>> {
/// Create a request to the sparse `index` and parse the response with the side-effect of yielding
/// the desired crate and updating the local cache.
fn update_cache(name: &str, index: &SparseIndex) -> Result<Option<Crate>, Box<dyn Error>> {
let request: ureq::Request = index.make_cache_request(name)?.try_into()?;
let request = index
.make_cache_request(name)?
.version(ureq::http::Version::HTTP_11)
.body(())?;

let response: http::Response<String> = match request.call() {
Ok(response) => response.into(),
Err(_) => return Ok(None),
};

let (parts, body) = response.into_parts();
let response = http::Response::from_parts(parts, body.into_bytes());
let response = ureq::run(request)?;

let (parts, mut body) = response.into_parts();
let response = http::Response::from_parts(parts, body.read_to_vec()?);
Ok(index.parse_cache_response(name, response, true)?)
}

Expand Down
21 changes: 11 additions & 10 deletions examples/sparse_http_ureq.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use crates_index::SparseIndex;
use std::io;

///
/// **important**:<br>
/// dont forget to enable the **http-interop** feature of **ureq**
///
/// command to run:<br>
/// cargo run --example sparse_http_ureq -F sparse
Expand Down Expand Up @@ -31,12 +27,17 @@ fn print_crate(index: &mut SparseIndex) {
}

fn update(index: &mut SparseIndex) {
let request: ureq::Request = index.make_cache_request(CRATE_TO_FETCH).unwrap().try_into().unwrap();

let response = request
.call()
.map_err(|_e| io::Error::new(io::ErrorKind::InvalidInput, "connection error"))
// ureq doesn't support HTTP/2, so we have to set the version to HTTP/1.1
let request = index
.make_cache_request(CRATE_TO_FETCH)
.unwrap()
.version(ureq::http::Version::HTTP_11)
.body(())
.unwrap();

index.parse_cache_response(CRATE_TO_FETCH, response.into(), true).unwrap();
let response = ureq::run(request).unwrap();

let (parts, mut body) = response.into_parts();
let response = http::Response::from_parts(parts, body.read_to_vec().unwrap());
index.parse_cache_response(CRATE_TO_FETCH, response, true).unwrap();
}
Loading