mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-01 17:45:35 +00:00
initial commit
This commit is contained in:
parent
381a398de1
commit
a7083852c3
22 changed files with 446 additions and 15 deletions
42
src/client/response.rs
Normal file
42
src/client/response.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
pub mod body;
|
||||
pub mod error;
|
||||
pub mod header;
|
||||
|
||||
pub use body::Body;
|
||||
pub use error::Error;
|
||||
pub use header::Header;
|
||||
|
||||
pub struct Response {
|
||||
header: Header,
|
||||
body: Body,
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Create new `client::Response`
|
||||
pub fn new(header: Header, body: Body) -> Self {
|
||||
Self { header, body }
|
||||
}
|
||||
|
||||
/// Create new `client::Response` from UTF-8 buffer
|
||||
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
||||
let header = match Header::from_response(buffer) {
|
||||
Ok(result) => result,
|
||||
Err(_) => return Err(Error::Header),
|
||||
};
|
||||
|
||||
let body = match Body::from_response(buffer) {
|
||||
Ok(result) => result,
|
||||
Err(_) => return Err(Error::Body),
|
||||
};
|
||||
|
||||
Ok(Self::new(header, body))
|
||||
}
|
||||
|
||||
pub fn header(&self) -> &Header {
|
||||
&self.header
|
||||
}
|
||||
|
||||
pub fn body(&self) -> &Body {
|
||||
&self.body
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue