tame_index/index/local/
builder.rs1use crate::Error;
4
5#[derive(Clone)]
8pub struct Client {
9 inner: reqwest::blocking::Client,
10}
11
12impl Client {
13 pub fn build(builder: reqwest::blocking::ClientBuilder) -> Result<Self, Error> {
15 let inner = builder.no_gzip().build()?;
20 Ok(Self { inner })
21 }
22}
23
24impl<'iv> super::ValidKrate<'iv> {
25 pub fn download(
27 client: &Client,
28 config: &crate::index::IndexConfig,
29 version: &'iv crate::IndexVersion,
30 ) -> Result<Self, Error> {
31 let url = config.download_url(version.name.as_str().try_into()?, version.version.as_ref());
32
33 let res = client.inner.get(url).send()?.error_for_status()?;
34 let body = res.bytes()?;
35 Self::validate(body, version)
36 }
37}