Compare commits
2 commits
19e1148989
...
16af1c1bd0
Author | SHA1 | Date | |
---|---|---|---|
16af1c1bd0 | |||
2ca51a5a20 |
3 changed files with 26 additions and 9 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -49,9 +49,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.6.1"
|
version = "1.7.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952"
|
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
|
@ -160,9 +160,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.2.6"
|
version = "2.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
|
checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"equivalent",
|
"equivalent",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
|
@ -414,6 +414,7 @@ name = "tokio-gemini"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64ct",
|
"base64ct",
|
||||||
|
"bytes",
|
||||||
"mime",
|
"mime",
|
||||||
"num_enum",
|
"num_enum",
|
||||||
"sha2",
|
"sha2",
|
||||||
|
|
|
@ -11,6 +11,7 @@ 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"
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
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,
|
||||||
body: BodyStream,
|
stream: BodyStream,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
pub fn new(status: Status, message: String, body: BodyStream) -> Self {
|
pub fn new(status: Status, message: String, stream: BodyStream) -> Self {
|
||||||
Response {
|
Response {
|
||||||
status,
|
status,
|
||||||
message,
|
message,
|
||||||
body,
|
stream,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +33,19 @@ impl Response {
|
||||||
self.message.parse().map_err(|e| LibError::InvalidMime(e))
|
self.message.parse().map_err(|e| LibError::InvalidMime(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn body(self: &mut Self) -> &mut BodyStream {
|
pub fn stream(self: &mut Self) -> &mut BodyStream {
|
||||||
&mut self.body
|
&mut self.stream
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue