Skip to content

Commit

Permalink
feat: Rename RootCertsStore to RootCertStore (#353)
Browse files Browse the repository at this point in the history
* feat: Rename `RootCertsStore` to `RootCertsStore`

* Update examples

* Move `RootCertStore` to tls/ext/cert

* Update ci.yml
  • Loading branch information
0x676e67 authored Jan 22, 2025
1 parent 98c61c8 commit 152142f
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 236 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ jobs:
run: |
sudo apt update && sudo apt install cmake build-essential clang libclang-dev -y
- name: Build
run: |
cargo build --all-features
- name: Tests
- name: Build & Tests
run: |
cargo test --all-features
Expand Down
5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,6 @@ name = "websocket"
path = "examples/websocket.rs"
required-features = ["websocket", "futures-util/std"]

[[example]]
name = "client"
path = "examples/client.rs"
required-features = ["full"]

[[example]]
name = "client_chain"
path = "examples/client_chain.rs"
Expand Down
101 changes: 0 additions & 101 deletions examples/client.rs

This file was deleted.

9 changes: 7 additions & 2 deletions examples/hickory_dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ async fn main() -> Result<(), rquest::Error> {
.build()?;

// Use the API you're already familiar with
let resp = client.get("https://tls.peet.ws/api/all").send().await?;
println!("{}", resp.text().await?);
let text = client
.get("https://tls.peet.ws/api/all")
.send()
.await?
.text()
.await?;
println!("{}", text);

Ok(())
}
1 change: 0 additions & 1 deletion examples/impersonate_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ async fn main() -> Result<(), rquest::Error> {
.await?
.text()
.await?;

println!("{}", text);

Ok(())
Expand Down
9 changes: 7 additions & 2 deletions examples/impersonate_psk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ async fn main() -> Result<(), rquest::Error> {
let _ = client.get("https://tls.peet.ws/api/all").send().await?;

// Now, let's impersonate a PSK
let resp = client.get("https://tls.peet.ws/api/all").send().await?;
println!("{}", resp.text().await?);
let text = client
.get("https://tls.peet.ws/api/all")
.send()
.await?
.text()
.await?;
println!("{}", text);

Ok(())
}
1 change: 0 additions & 1 deletion examples/request_with_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ async fn main() -> Result<(), rquest::Error> {
.await?
.text()
.await?;

println!("{}", text);

Ok(())
Expand Down
1 change: 0 additions & 1 deletion examples/request_with_local_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ async fn main() -> Result<(), rquest::Error> {
.send()
.await?;

println!("{:?}", resp.version());
println!("{}", resp.text().await?);

Ok(())
Expand Down
5 changes: 3 additions & 2 deletions examples/request_with_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ async fn main() -> Result<(), rquest::Error> {
.get("https://tls.peet.ws/api/all")
.proxy("http://127.0.0.1:6152")
.send()
.await?
.text()
.await?;

println!("{}", resp.text().await?);
println!("{}", resp);

Ok(())
}
5 changes: 3 additions & 2 deletions examples/request_with_redirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ async fn main() -> Result<(), rquest::Error> {
.get("http://google.com/")
.redirect(Policy::default())
.send()
.await?
.text()
.await?;

println!("{}", resp.text().await?);
println!("{}", resp);

Ok(())
}
4 changes: 2 additions & 2 deletions examples/set_cookie_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ async fn main() -> Result<(), rquest::Error> {
);

// Use the API you're already familiar with
let resp = client.get(url).send().await?;
println!("{}", resp.text().await?);
let resp = client.get(url).send().await?.text().await?;
println!("{}", resp);

Ok(())
}
14 changes: 6 additions & 8 deletions examples/set_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ async fn main() -> Result<(), rquest::Error> {
println!("{}", resp.text().await?);

// Set a header
{
client
.as_mut()
.headers()
.insert(header::ACCEPT, HeaderValue::from_static("application/json"));
let resp = client.get("https://tls.peet.ws/api/all").send().await?;
println!("{}", resp.text().await?);
}
client
.as_mut()
.headers()
.insert(header::ACCEPT, HeaderValue::from_static("application/json"));
let resp = client.get("https://tls.peet.ws/api/all").send().await?;
println!("{}", resp.text().await?);

Ok(())
}
23 changes: 6 additions & 17 deletions examples/set_impersonate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,14 @@ async fn main() -> Result<(), rquest::Error> {
.build()?;

// Set the headers order
{
client.as_mut().headers_order(&HEADER_ORDER);
let resp = client.get("https://tls.peet.ws/api/all").send().await?;
println!("{}", resp.text().await?);
}
client.as_mut().headers_order(&HEADER_ORDER);
let resp = client.get("https://tls.peet.ws/api/all").send().await?;
println!("{}", resp.text().await?);

// Change the impersonate to Safari18
{
client.as_mut().impersonate(Impersonate::Safari18);
let resp = client.get("https://tls.peet.ws/api/all").send().await?;
println!("{}", resp.text().await?);
}

// Change the impersonate to Edge127 without setting the headers
{
client.as_mut().impersonate(Impersonate::Edge127);
let resp = client.get("https://tls.peet.ws/api/all").send().await?;
println!("{}", resp.text().await?);
}
client.as_mut().impersonate(Impersonate::Safari18);
let resp = client.get("https://tls.peet.ws/api/all").send().await?;
println!("{}", resp.text().await?);

Ok(())
}
5 changes: 2 additions & 3 deletions examples/set_proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ async fn main() -> Result<(), rquest::Error> {
println!("{}", resp.text().await?);
}

// option 2: the proxies
// option 2: clear the proxies
{
let proxy = rquest::Proxy::all("socks5h://abc:[email protected]:6153")?;
client.as_mut().proxies(vec![proxy]);
client.as_mut().proxies(None);

let resp = client.get("https://api.ip.sb/ip").send().await?;
println!("{}", resp.text().await?);
Expand Down
9 changes: 7 additions & 2 deletions examples/set_redirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ async fn main() -> Result<(), rquest::Error> {
// Set the redirect policy
client.as_mut().redirect(Policy::default());

let resp = client.get("http://google.com/").send().await?;
let text = client
.get("http://google.com/")
.send()
.await?
.text()
.await?;

println!("{}", resp.text().await?);
println!("{}", text);

Ok(())
}
4 changes: 2 additions & 2 deletions examples/set_root_cert_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn load_dynamic_root_certs() -> Result<X509Store, Error> {

async fn use_static_root_certs() -> Result<(), rquest::Error> {
let client = Client::builder()
.root_certs_store(load_static_root_certs)
.root_cert_store(load_static_root_certs)
.build()?;

let text = client
Expand All @@ -63,7 +63,7 @@ async fn use_static_root_certs() -> Result<(), rquest::Error> {

async fn use_dynamic_root_certs() -> Result<(), rquest::Error> {
let client = Client::builder()
.root_certs_store(load_dynamic_root_certs()?)
.root_cert_store(load_dynamic_root_certs()?)
.build()?;

let text = client
Expand Down
6 changes: 3 additions & 3 deletions src/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use crate::into_url::try_uri;
use crate::{cfg_bindable_device, error, impl_debug};
use crate::{
redirect,
tls::{AlpnProtos, BoringTlsConnector, RootCertsStore, TlsVersion},
tls::{AlpnProtos, BoringTlsConnector, RootCertStore, TlsVersion},
};
use crate::{IntoUrl, Method, Proxy, StatusCode, Url};
#[cfg(feature = "hickory-dns")]
Expand Down Expand Up @@ -1058,9 +1058,9 @@ impl ClientBuilder {
}

/// Set root certificate store.
pub fn root_certs_store<S>(mut self, store: S) -> ClientBuilder
pub fn root_cert_store<S>(mut self, store: S) -> ClientBuilder
where
S: Into<RootCertsStore>,
S: Into<RootCertStore>,
{
self.config.settings.tls.root_certs_store = store.into();
self
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub use self::client::{Body, Client, ClientBuilder, Request, RequestBuilder, Res
pub use self::imp::{Impersonate, ImpersonateBuilder, ImpersonateOS, ImpersonateSettings};
pub use self::proxy::{NoProxy, Proxy};
pub use self::tls::{
AlpnProtos, AlpsProtos, CertCompressionAlgorithm, RootCertsStore, TlsInfo, TlsSettings,
AlpnProtos, AlpsProtos, CertCompressionAlgorithm, RootCertStore, TlsInfo, TlsSettings,
TlsVersion,
};
pub use self::util::client::Dst;
Expand Down
File renamed without changes.
16 changes: 12 additions & 4 deletions src/tls/ext/cert_load.rs → src/tls/ext/cert/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@ use boring2::x509::{store::X509StoreBuilder, X509};
use boring2::{error::ErrorStack, x509::store::X509Store};
use std::sync::LazyLock;

pub static LOAD_CERTS: LazyLock<Result<X509Store, crate::Error>> = LazyLock::new(|| {
pub static LOAD_CERTS: LazyLock<Option<X509Store>> = LazyLock::new(|| {
#[cfg(feature = "webpki-roots")]
{
let res = {
load_certs_from_source(
webpki_root_certs::TLS_SERVER_ROOT_CERTS
.iter()
.map(|c| X509::from_der(c)),
)
}
};

#[cfg(all(feature = "native-roots", not(feature = "webpki-roots")))]
{
let res = {
load_certs_from_source(
rustls_native_certs::load_native_certs()
.iter()
.map(|c| X509::from_der(&*c)),
)
};

match res {
Ok(store) => Some(store),
Err(err) => {
log::error!("tls failed to load root certificates: {err}");
None
}
}
});

Expand Down
Loading

0 comments on commit 152142f

Please sign in to comment.