Update to tungstenite 0.13

And improve error mapping.

Fixes https://github.com/sdroege/async-tungstenite/issues/79
pull/83/head
Sebastian Dröge 4 years ago committed by Sebastian Dröge
parent f51f074491
commit 24cae74484
  1. 10
      Cargo.toml
  2. 6
      src/async_std.rs
  3. 6
      src/lib.rs
  4. 4
      src/tokio/dummy_tls.rs
  5. 6
      src/tokio/native_tls.rs
  6. 7
      src/tokio/rustls.rs

@ -8,7 +8,7 @@ license = "MIT"
homepage = "https://github.com/sdroege/async-tungstenite" homepage = "https://github.com/sdroege/async-tungstenite"
repository = "https://github.com/sdroege/async-tungstenite" repository = "https://github.com/sdroege/async-tungstenite"
documentation = "https://docs.rs/async-tungstenite" documentation = "https://docs.rs/async-tungstenite"
version = "0.12.0" version = "0.13.0"
edition = "2018" edition = "2018"
readme = "README.md" readme = "README.md"
@ -18,9 +18,9 @@ async-std-runtime = ["async-std"]
tokio-runtime = ["tokio"] 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", "tungstenite/native-tls"]
tokio-native-tls = ["tokio-runtime", "real-tokio-native-tls", "real-native-tls", "tungstenite/tls"] tokio-native-tls = ["tokio-runtime", "real-tokio-native-tls", "real-native-tls", "tungstenite/native-tls"]
tokio-rustls = ["tokio-runtime", "real-tokio-rustls", "webpki-roots"] tokio-rustls = ["tokio-runtime", "real-tokio-rustls", "webpki-roots", "tungstenite/rustls-tls"]
tokio-openssl = ["tokio-runtime", "real-tokio-openssl", "openssl"] tokio-openssl = ["tokio-runtime", "real-tokio-openssl", "openssl"]
[package.metadata.docs.rs] [package.metadata.docs.rs]
@ -33,7 +33,7 @@ futures-io = { version = "0.3", default-features = false, features = ["std"] }
pin-project-lite = "0.2" pin-project-lite = "0.2"
[dependencies.tungstenite] [dependencies.tungstenite]
version = "0.12.0" version = "0.13.0"
default-features = false default-features = false
[dependencies.async-std] [dependencies.async-std]

@ -58,7 +58,7 @@ pub(crate) mod async_native_tls {
connector connector
.connect(&domain, socket) .connect(&domain, socket)
.await .await
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))? .map_err(|err| Error::Tls(err.into()))?
}; };
Ok(StreamSwitcher::Tls(stream)) Ok(StreamSwitcher::Tls(stream))
} }
@ -116,7 +116,9 @@ pub(crate) mod dummy_tls {
{ {
match mode { match mode {
Mode::Plain => Ok(socket), Mode::Plain => Ok(socket),
Mode::Tls => Err(Error::Url("TLS support not compiled in.".into())), Mode::Tls => Err(Error::Url(
tungstenite::error::UrlError::TlsFeatureNotEnabled,
)),
} }
} }

@ -370,7 +370,9 @@ pub(crate) fn domain(
) -> Result<String, tungstenite::Error> { ) -> Result<String, tungstenite::Error> {
match request.uri().host() { match request.uri().host() {
Some(d) => Ok(d.to_string()), Some(d) => Ok(d.to_string()),
None => Err(tungstenite::Error::Url("no host name in the url".into())), None => Err(tungstenite::Error::Url(
tungstenite::error::UrlError::NoHostName,
)),
} }
} }
@ -392,5 +394,5 @@ pub(crate) fn port(
Some("ws") => Some(80), Some("ws") => Some(80),
_ => None, _ => None,
}) })
.ok_or_else(|| tungstenite::Error::Url("Url scheme not supported".into())) .ok_or_else(|| tungstenite::Error::Url(tungstenite::error::UrlError::UnsupportedUrlScheme))
} }

@ -22,7 +22,9 @@ where
{ {
match mode { match mode {
Mode::Plain => Ok(TokioAdapter::new(socket)), Mode::Plain => Ok(TokioAdapter::new(socket)),
Mode::Tls => Err(Error::Url("TLS support not compiled in.".into())), Mode::Tls => Err(Error::Url(
tungstenite::error::UrlError::TlsFeatureNotEnabled,
)),
} }
} }

@ -34,13 +34,15 @@ where
let connector = if let Some(connector) = connector { let connector = if let Some(connector) = connector {
connector connector
} else { } else {
let connector = real_native_tls::TlsConnector::builder().build()?; let connector = real_native_tls::TlsConnector::builder()
.build()
.map_err(|err| Error::Tls(err.into()))?;
AsyncTlsConnector::from(connector) AsyncTlsConnector::from(connector)
}; };
connector connector
.connect(&domain, socket) .connect(&domain, socket)
.await .await
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))? .map_err(|err| Error::Tls(err.into()))?
}; };
Ok(StreamSwitcher::Tls(TokioAdapter::new(stream))) Ok(StreamSwitcher::Tls(TokioAdapter::new(stream)))
} }

@ -42,11 +42,8 @@ where
TlsConnector::from(std::sync::Arc::new(config)) TlsConnector::from(std::sync::Arc::new(config))
}; };
let domain = DNSNameRef::try_from_ascii_str(&domain) let domain = DNSNameRef::try_from_ascii_str(&domain)
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?; .map_err(|err| Error::Tls(err.into()))?;
connector connector.connect(domain, socket).await?
.connect(domain, socket)
.await
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?
}; };
Ok(StreamSwitcher::Tls(TokioAdapter::new(stream))) Ok(StreamSwitcher::Tls(TokioAdapter::new(stream)))
} }

Loading…
Cancel
Save