Compare commits

..

No commits in common. "16af1c1bd0bdd4e8d5fbe85fd36df23c681b0f8e" and "19e11489891b988fdb15e5b2af183d9cbd8a1647" have entirely different histories.

3 changed files with 9 additions and 26 deletions

9
Cargo.lock generated
View file

@ -49,9 +49,9 @@ dependencies = [
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.7.1" version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952"
[[package]] [[package]]
name = "cc" name = "cc"
@ -160,9 +160,9 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.3.0" version = "2.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
dependencies = [ dependencies = [
"equivalent", "equivalent",
"hashbrown", "hashbrown",
@ -414,7 +414,6 @@ name = "tokio-gemini"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"base64ct", "base64ct",
"bytes",
"mime", "mime",
"num_enum", "num_enum",
"sha2", "sha2",

View file

@ -11,7 +11,6 @@ categories = ["network-programming"]
[dependencies] [dependencies]
base64ct = "1.6.0" base64ct = "1.6.0"
bytes = "1.7.1"
mime = "0.3.17" mime = "0.3.17"
num_enum = "0.7.3" num_enum = "0.7.3"
sha2 = "0.10.8" sha2 = "0.10.8"

View file

@ -1,23 +1,20 @@
use crate::{status::Status, LibError}; use crate::{status::Status, LibError};
use bytes::Bytes;
use tokio::io::AsyncReadExt;
type BodyStream = tokio_rustls::client::TlsStream<tokio::net::TcpStream>; type BodyStream = tokio_rustls::client::TlsStream<tokio::net::TcpStream>;
#[derive(Debug)] #[derive(Debug)]
pub struct Response { pub struct Response {
status: Status, status: Status,
message: String, message: String,
stream: BodyStream, body: BodyStream,
} }
impl Response { impl Response {
pub fn new(status: Status, message: String, stream: BodyStream) -> Self { pub fn new(status: Status, message: String, body: BodyStream) -> Self {
Response { Response {
status, status,
message, message,
stream, body,
} }
} }
@ -33,19 +30,7 @@ impl Response {
self.message.parse().map_err(|e| LibError::InvalidMime(e)) self.message.parse().map_err(|e| LibError::InvalidMime(e))
} }
pub fn stream(self: &mut Self) -> &mut BodyStream { pub fn body(self: &mut Self) -> &mut BodyStream {
&mut self.stream &mut self.body
}
pub async fn bytes(self: &mut Self) -> Result<Bytes, LibError> {
let mut buf = Vec::new();
self.stream.read_to_end(&mut buf).await?;
Ok(Bytes::from(buf))
}
pub async fn text(self: &mut Self) -> Result<String, LibError> {
let mut buf = String::new();
self.stream.read_to_string(&mut buf).await?;
Ok(buf)
} }
} }