use async-std and tokio i guess
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
564eb3990c
commit
2bc1aa315f
|
@ -2,7 +2,7 @@
|
|||
|
||||
## 0.4.0
|
||||
|
||||
Tokio has been purged. This crate now uses async-std.
|
||||
Tokio has been somewhat purged.
|
||||
|
||||
## 0.3.0
|
||||
|
||||
|
|
|
@ -15,8 +15,10 @@ num = "0.2"
|
|||
num-derive = "0.3"
|
||||
num-traits = "0.2"
|
||||
rustls = { version = "0.18", optional = true, features = ["dangerous_configuration"] }
|
||||
tokio-rustls = { version = "0.14", features = ["dangerous_configuration"], optional = true }
|
||||
webpki = { version = "0.21.0", optional = true }
|
||||
webpki-roots = { version = "0.20", optional = true }
|
||||
tokio = { version = "0.2", features = ["full"], optional = true }
|
||||
async-tls = { version = "0.9.0", default-features = false, optional = true }
|
||||
async-std = { version = "1.6", optional = true }
|
||||
log = "0.4"
|
||||
|
@ -32,9 +34,10 @@ pretty_env_logger = "0.4"
|
|||
default = ["client", "server"]
|
||||
|
||||
client = [
|
||||
"rustls",
|
||||
"tokio-rustls",
|
||||
"webpki",
|
||||
"webpki-roots",
|
||||
"tokio",
|
||||
"async-std",
|
||||
"async-tls/client"
|
||||
]
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
use crate::Response;
|
||||
use async_std::{io::prelude::*, net::TcpStream};
|
||||
use async_tls::TlsConnector;
|
||||
use rustls::TLSError;
|
||||
use std::{io::Cursor, sync::Arc};
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
net::TcpStream,
|
||||
};
|
||||
use tokio_rustls::{
|
||||
rustls::{TLSError},
|
||||
TlsConnector,
|
||||
};
|
||||
use url::Url;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
|
@ -26,7 +31,7 @@ pub enum Error {
|
|||
InvalidScheme(String),
|
||||
}
|
||||
|
||||
pub async fn get<T>(u: T, cfg: rustls::ClientConfig) -> Result<crate::Response, Error>
|
||||
pub async fn get<T>(u: T, cfg: tokio_rustls::rustls::ClientConfig) -> Result<crate::Response, Error>
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
|
@ -42,10 +47,11 @@ where
|
|||
|
||||
let cfg = Arc::new(cfg);
|
||||
let host = ur.host_str().unwrap();
|
||||
let name_ref = webpki::DNSNameRef::try_from_ascii_str(host)?;
|
||||
let config = TlsConnector::from(cfg);
|
||||
|
||||
let sock = TcpStream::connect(&format!("{}:{}", host, ur.port().unwrap())).await?;
|
||||
let mut tls = config.connect(host, sock).await?;
|
||||
let mut tls = config.connect(name_ref, sock).await?;
|
||||
|
||||
let req = format!("{}\r\n", u);
|
||||
log::trace!("writing request {:?}", req);
|
||||
|
@ -57,6 +63,8 @@ where
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use tokio_rustls::rustls;
|
||||
|
||||
fn config() -> rustls::ClientConfig {
|
||||
let mut config = rustls::ClientConfig::new();
|
||||
config
|
||||
|
|
Loading…
Reference in New Issue