Skip to content

Commit

Permalink
Merge branch 'master' into feat/taosdata/permessage-deflate
Browse files Browse the repository at this point in the history
* master:
  deps: update `rustls-native-certs` to 0.8 (snapview#348)
  Additional Documentation of `IntoClientRequest` on `connect_async` (snapview#342)
  Prepare 0.23.1 release
  • Loading branch information
zitsen committed Sep 9, 2024
2 parents 858ce5f + 0b9d97b commit 19822e0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Unreleased
# 0.23.1

- Introduce a `url` feature (proxies to `tungstenite/url`).

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ keywords = ["websocket", "io", "web"]
authors = ["Daniel Abramov <dabramov@snapview.de>", "Alexey Galakhov <agalakhov@snapview.de>"]
license = "MIT"
homepage = "https://github.com/snapview/tokio-tungstenite"
documentation = "https://docs.rs/tokio-tungstenite/0.23.0"
documentation = "https://docs.rs/tokio-tungstenite/0.23.1"
repository = "https://github.com/snapview/tokio-tungstenite"
version = "0.23.0"
version = "0.23.1"
edition = "2018"
rust-version = "1.63"
include = ["examples/**/*", "src/**/*", "LICENSE", "README.md", "CHANGELOG.md"]
Expand Down Expand Up @@ -60,7 +60,7 @@ version = "1.0"

[dependencies.rustls-native-certs]
optional = true
version = "0.7.0"
version = "0.8.0"

[dependencies.tokio-native-tls]
optional = true
Expand Down
18 changes: 18 additions & 0 deletions src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ use tungstenite::{
use crate::{domain, stream::MaybeTlsStream, Connector, IntoClientRequest, WebSocketStream};

/// Connect to a given URL.
///
/// Accepts any request that implements [`IntoClientRequest`], which is often just `&str`, but can
/// be a variety of types such as `httparse::Request` or [`tungstenite::http::Request`] for more
/// complex uses.
///
/// ```no_run
/// # use tungstenite::client::IntoClientRequest;
///
/// # async fn test() {
/// use tungstenite::http::{Method, Request};
/// use tokio_tungstenite::connect_async;
///
/// let mut request = "wss://api.example.com".into_client_request().unwrap();
/// request.headers_mut().insert("api-key", "42".parse().unwrap());
///
/// let (stream, response) = connect_async(request).await.unwrap();
/// # }
/// ```
pub async fn connect_async<R>(
request: R,
) -> Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Response), Error>
Expand Down
22 changes: 19 additions & 3 deletions src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,26 @@ mod encryption {
let mut root_store = RootCertStore::empty();
#[cfg(feature = "rustls-tls-native-roots")]
{
let native_certs = rustls_native_certs::load_native_certs()?;
let total_number = native_certs.len();
let rustls_native_certs::CertificateResult {
certs, errors, ..
} = rustls_native_certs::load_native_certs();

if !errors.is_empty() {
log::warn!(
"native root CA certificate loading errors: {errors:?}"
);
}

// Not finding any native root CA certificates is not fatal if the
// "rustls-tls-webpki-roots" feature is enabled.
#[cfg(not(feature = "rustls-tls-webpki-roots"))]
if certs.is_empty() {
return Err(std::io::Error::new(std::io::ErrorKind::NotFound, format!("no native root CA certificates found (errors: {errors:?})")).into());
}

let total_number = certs.len();
let (number_added, number_ignored) =
root_store.add_parsable_certificates(native_certs);
root_store.add_parsable_certificates(certs);
log::debug!("Added {number_added}/{total_number} native root certificates (ignored {number_ignored})");
}
#[cfg(feature = "rustls-tls-webpki-roots")]
Expand Down

0 comments on commit 19822e0

Please sign in to comment.