Switch from deprecated tokio-tls to tokio-native-tls

pull/32/head
Sebastian Dröge 5 years ago
parent cba1d7bb32
commit 29e528d1bc
  1. 10
      Cargo.toml
  2. 4
      README.md
  3. 4
      examples/tokio-echo.rs
  4. 6
      src/lib.rs
  5. 26
      src/tokio.rs

@ -19,10 +19,10 @@ tokio-runtime = ["tokio"]
gio-runtime = ["gio", "glib"] gio-runtime = ["gio", "glib"]
async-tls = ["real-async-tls"] async-tls = ["real-async-tls"]
async-native-tls = ["async-std-runtime", "real-async-native-tls"] async-native-tls = ["async-std-runtime", "real-async-native-tls"]
tokio-tls = ["tokio-runtime", "real-tokio-tls", "real-native-tls", "tungstenite/tls"] tokio-native-tls = ["tokio-runtime", "real-tokio-native-tls", "real-native-tls", "tungstenite/tls"]
[package.metadata.docs.rs] [package.metadata.docs.rs]
features = ["async-std-runtime", "tokio-runtime", "gio-runtime", "async-tls", "async-native-tls", "tokio-tls"] features = ["async-std-runtime", "tokio-runtime", "gio-runtime", "async-tls", "async-native-tls", "tokio-native-tls"]
[dependencies] [dependencies]
log = "0.4" log = "0.4"
@ -58,10 +58,10 @@ optional = true
version = "0.2" version = "0.2"
features = ["tcp", "dns"] features = ["tcp", "dns"]
[dependencies.real-tokio-tls] [dependencies.real-tokio-native-tls]
optional = true optional = true
version = "0.3" version = "0.1"
package = "tokio-tls" package = "tokio-native-tls"
[dependencies.gio] [dependencies.gio]
optional = true optional = true

@ -41,8 +41,8 @@ integration with various other crates can be enabled via feature flags
[async-native-tls](https://crates.io/crates/async-native-tls). [async-native-tls](https://crates.io/crates/async-native-tls).
* `tokio-runtime`: Enables the `tokio` module, which provides integration * `tokio-runtime`: Enables the `tokio` module, which provides integration
with the [tokio](https://tokio.rs) runtime. with the [tokio](https://tokio.rs) runtime.
* `tokio-tls`: Enables the additional functions in the `tokio` module to * `tokio-native-tls`: Enables the additional functions in the `tokio` module to
implement TLS via [tokio-tls](https://crates.io/crates/tokio-tls). implement TLS via [tokio-native-tls](https://crates.io/crates/tokio-native-tls).
* `gio-runtime`: Enables the `gio` module, which provides integration with * `gio-runtime`: Enables the `gio` module, which provides integration with
the [gio](https://gtk-rs.org) runtime. the [gio](https://gtk-rs.org) runtime.

@ -2,9 +2,9 @@ use async_tungstenite::{tokio::connect_async, tungstenite::Message};
use futures::prelude::*; use futures::prelude::*;
async fn run() -> Result<(), Box<dyn std::error::Error>> { async fn run() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(any(feature = "async-tls", feature = "tokio-tls"))] #[cfg(any(feature = "async-tls", feature = "tokio-native-tls"))]
let url = "wss://echo.websocket.org"; let url = "wss://echo.websocket.org";
#[cfg(not(any(feature = "async-tls", feature = "tokio-tls")))] #[cfg(not(any(feature = "async-tls", feature = "tokio-native-tls")))]
let url = "ws://echo.websocket.org"; let url = "ws://echo.websocket.org";
let (mut ws_stream, _) = connect_async(url).await?; let (mut ws_stream, _) = connect_async(url).await?;

@ -16,8 +16,8 @@
//! [async-native-tls](https://crates.io/crates/async-native-tls). //! [async-native-tls](https://crates.io/crates/async-native-tls).
//! * `tokio-runtime`: Enables the `tokio` module, which provides integration //! * `tokio-runtime`: Enables the `tokio` module, which provides integration
//! with the [tokio](https://tokio.rs) runtime. //! with the [tokio](https://tokio.rs) runtime.
//! * `tokio-tls`: Enables the additional functions in the `tokio` module to //! * `tokio-native-tls`: Enables the additional functions in the `tokio` module to
//! implement TLS via [tokio-tls](https://crates.io/crates/tokio-tls). //! implement TLS via [tokio-native-tls](https://crates.io/crates/tokio-native-tls).
//! * `gio-runtime`: Enables the `gio` module, which provides integration with //! * `gio-runtime`: Enables the `gio` module, which provides integration with
//! the [gio](https://www.gtk-rs.org) runtime. //! the [gio](https://www.gtk-rs.org) runtime.
//! //!
@ -41,7 +41,7 @@ mod handshake;
#[cfg(any( #[cfg(any(
feature = "async-tls", feature = "async-tls",
feature = "async-native-tls", feature = "async-native-tls",
feature = "tokio-tls", feature = "tokio-native-tls",
))] ))]
pub mod stream; pub mod stream;

@ -10,10 +10,10 @@ use super::{domain, port, WebSocketStream};
use futures_io::{AsyncRead, AsyncWrite}; use futures_io::{AsyncRead, AsyncWrite};
#[cfg(feature = "tokio-tls")] #[cfg(feature = "tokio-native-tls")]
pub(crate) mod tokio_tls { pub(crate) mod tokio_tls {
use real_tokio_tls::TlsConnector as AsyncTlsConnector; use real_tokio_native_tls::TlsConnector as AsyncTlsConnector;
use real_tokio_tls::TlsStream; use real_tokio_native_tls::TlsStream;
use tungstenite::client::{uri_mode, IntoClientRequest}; use tungstenite::client::{uri_mode, IntoClientRequest};
use tungstenite::handshake::client::Request; use tungstenite::handshake::client::Request;
@ -89,7 +89,7 @@ pub(crate) mod tokio_tls {
} }
} }
#[cfg(not(any(feature = "async-tls", feature = "tokio-tls")))] #[cfg(not(any(feature = "async-tls", feature = "tokio-native-tls")))]
pub(crate) mod dummy_tls { pub(crate) mod dummy_tls {
use futures_io::{AsyncRead, AsyncWrite}; use futures_io::{AsyncRead, AsyncWrite};
@ -141,18 +141,18 @@ pub(crate) mod dummy_tls {
} }
} }
#[cfg(not(any(feature = "async-tls", feature = "tokio-tls")))] #[cfg(not(any(feature = "async-tls", feature = "tokio-native-tls")))]
use self::dummy_tls::{client_async_tls_with_connector_and_config, AutoStream}; use self::dummy_tls::{client_async_tls_with_connector_and_config, AutoStream};
#[cfg(all(feature = "async-tls", not(feature = "tokio-tls")))] #[cfg(all(feature = "async-tls", not(feature = "tokio-native-tls")))]
use crate::async_tls::{client_async_tls_with_connector_and_config, AutoStream}; use crate::async_tls::{client_async_tls_with_connector_and_config, AutoStream};
#[cfg(all(feature = "async-tls", not(feature = "tokio-tls")))] #[cfg(all(feature = "async-tls", not(feature = "tokio-native-tls")))]
type Connector = real_async_tls::TlsConnector; type Connector = real_async_tls::TlsConnector;
#[cfg(feature = "tokio-tls")] #[cfg(feature = "tokio-native-tls")]
use self::tokio_tls::{client_async_tls_with_connector_and_config, AutoStream, Connector}; use self::tokio_tls::{client_async_tls_with_connector_and_config, AutoStream, Connector};
#[cfg(feature = "tokio-tls")] #[cfg(feature = "tokio-native-tls")]
/// Creates a WebSocket handshake from a request and a stream, /// Creates a WebSocket handshake from a request and a stream,
/// upgrading the stream to TLS if required. /// upgrading the stream to TLS if required.
pub async fn client_async_tls<R, S>( pub async fn client_async_tls<R, S>(
@ -167,7 +167,7 @@ where
client_async_tls_with_connector_and_config(request, stream, None, None).await client_async_tls_with_connector_and_config(request, stream, None, None).await
} }
#[cfg(feature = "tokio-tls")] #[cfg(feature = "tokio-native-tls")]
/// Creates a WebSocket handshake from a request and a stream, /// Creates a WebSocket handshake from a request and a stream,
/// upgrading the stream to TLS if required and using the given /// upgrading the stream to TLS if required and using the given
/// WebSocket configuration. /// WebSocket configuration.
@ -184,7 +184,7 @@ where
client_async_tls_with_connector_and_config(request, stream, None, config).await client_async_tls_with_connector_and_config(request, stream, None, config).await
} }
#[cfg(feature = "tokio-tls")] #[cfg(feature = "tokio-native-tls")]
/// Creates a WebSocket handshake from a request and a stream, /// Creates a WebSocket handshake from a request and a stream,
/// upgrading the stream to TLS if required and using the given /// upgrading the stream to TLS if required and using the given
/// connector. /// connector.
@ -241,7 +241,7 @@ where
client_async_tls_with_connector_and_config(request, TokioAdapter(socket), None, config).await client_async_tls_with_connector_and_config(request, TokioAdapter(socket), None, config).await
} }
#[cfg(any(feature = "async-tls", feature = "tokio-tls"))] #[cfg(any(feature = "async-tls", feature = "tokio-native-tls"))]
/// Connect to a given URL using the provided TLS connector. /// Connect to a given URL using the provided TLS connector.
pub async fn connect_async_with_tls_connector<R>( pub async fn connect_async_with_tls_connector<R>(
request: R, request: R,
@ -259,7 +259,7 @@ where
connect_async_with_tls_connector_and_config(request, connector, None).await connect_async_with_tls_connector_and_config(request, connector, None).await
} }
#[cfg(any(feature = "async-tls", feature = "tokio-tls"))] #[cfg(any(feature = "async-tls", feature = "tokio-native-tls"))]
/// Connect to a given URL using the provided TLS connector. /// Connect to a given URL using the provided TLS connector.
pub async fn connect_async_with_tls_connector_and_config<R>( pub async fn connect_async_with_tls_connector_and_config<R>(
request: R, request: R,

Loading…
Cancel
Save