use crate::host::{Body, Bytes, Header, handler};
pub struct Request {
header: Header,
body: Body,
}
static KIND_REQ: i32 = 0;
impl Default for Request {
fn default() -> Self {
Self {
header: Header::kind(KIND_REQ),
body: Body::kind(KIND_REQ),
}
}
}
impl Request {
pub fn source_addr(&self) -> Bytes {
Bytes::from(handler::source_addr())
}
pub fn version(&self) -> Bytes {
Bytes::from(handler::version())
}
pub fn method(&self) -> Bytes {
Bytes::from(handler::method())
}
pub fn set_method(&self, method: &[u8]) {
handler::set_method(method);
}
pub fn uri(&self) -> Bytes {
Bytes::from(handler::uri())
}
pub fn set_uri(&self, uri: &[u8]) {
handler::set_uri(uri);
}
pub fn header(&self) -> &Header {
&self.header
}
pub fn body(&self) -> &Body {
&self.body
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_method() {
let r = Request::default();
let sut = r.method();
assert_eq!("GET", sut.to_str().unwrap());
}
#[test]
fn test_version() {
let r = Request::default();
let sut = r.version();
assert!(!sut.is_empty());
assert_eq!(sut.as_ref(), b"HTTP/2.0");
}
}