diff --git a/src/client/mod.rs b/src/client/mod.rs index a498789..32d1f75 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -85,7 +85,7 @@ impl Client { /// - [`std::io::Error`] is returned in nearly all cases: /// could not open a TCP connection, perform a TLS handshake, /// write to or read from the TCP stream. - /// Check the inner error if you need to determine what exactly happened + /// Check the inner error if you need to determine what exactly happened. /// - [`LibError::StatusOutOfRange`] means that a server returned an incorrect status code /// (less than 10 or greater than 69). /// - [`LibError::DataNotUtf8`] is returned when metadata (the text after a status code) @@ -100,9 +100,12 @@ impl Client { .map_err(|_| InvalidUrl::ConvertError)? .to_owned(); + // TCP connection let stream = self.try_connect(host, port).await?; - let mut stream = self.connector.connect(domain, stream).await?; + // TLS connection via tokio-rustls + let stream = self.connector.connect(domain, stream).await?; + // certificate verification if let Some(ssv) = &self.ss_verifier { let cert = stream .get_ref() @@ -117,6 +120,14 @@ impl Client { } } + self.perform_io(url_str, stream).await + } + + pub(crate) async fn perform_io( + &self, + url_str: &str, + mut stream: IO, + ) -> Result>, LibError> { // Write URL, then CRLF stream.write_all(url_str.as_bytes()).await?; stream.write_all(b"\r\n").await?;