diff --git a/src/client/mod.rs b/src/client/mod.rs index 7612610..a498789 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -22,12 +22,14 @@ use builder::ClientBuilder; use std::sync::Arc; use tokio::{ - io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt}, + io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader}, net::TcpStream, }; -use tokio_rustls::{rustls, TlsConnector}; +use tokio_rustls::{client::TlsStream, rustls, TlsConnector}; use url::Url; +pub type ThisResponse = Response>>; + pub struct Client { pub(crate) connector: TlsConnector, pub(crate) ss_verifier: Option>, @@ -56,7 +58,7 @@ impl Client { /// - [`InvalidUrl::UserinfoPresent`] is returned when the URL contains userinfo -- `user:password@` -- /// which is forbidden by the Gemini specs. /// - For the rest, see [`Client::request_with_host`]. - pub async fn request(&self, url_str: &str) -> Result { + pub async fn request(&self, url_str: &str) -> Result { let url = Url::parse(url_str).map_err(InvalidUrl::ParseError)?; // deny non-Gemini requests if url.scheme() != "gemini" { @@ -93,7 +95,7 @@ impl Client { url_str: &str, host: &str, port: u16, - ) -> Result { + ) -> Result { let domain = ServerName::try_from(host) .map_err(|_| InvalidUrl::ConvertError)? .to_owned(); @@ -126,7 +128,7 @@ impl Client { Status::parse_status(&buf)? }; - let mut stream = tokio::io::BufReader::new(stream); + let mut stream = BufReader::new(stream); let message = { let mut result: Vec = Vec::new(); diff --git a/src/client/response.rs b/src/client/response.rs index a995cde..b69ea95 100644 --- a/src/client/response.rs +++ b/src/client/response.rs @@ -5,19 +5,17 @@ use crate::{status::Status, LibError, ReplyType}; use bytes::Bytes; use tokio::io::AsyncReadExt; -type BodyStream = tokio::io::BufReader>; - /// Client-side response structure wrapping a [`Status`], /// a metadata string and a TLS stream #[derive(Debug)] -pub struct Response { +pub struct Response { status: Status, message: String, - stream: BodyStream, + stream: IO, } -impl Response { - pub fn new(status: Status, message: String, stream: BodyStream) -> Self { +impl Response { + pub fn new(status: Status, message: String, stream: IO) -> Self { Response { status, message, @@ -82,7 +80,7 @@ impl Response { /// so calling `.bytes()` after `.stream().read_to_end(…)` /// (or `.bytes()` twice, or `.text()` after `.bytes()` and vice versa) /// on the same response will result in empty output. - pub fn stream(&mut self) -> &mut BodyStream { + pub fn stream(&mut self) -> &mut IO { &mut self.stream }