use hyper::body::Incoming;
use hyper::{Method, Uri};
use hyper::header::HeaderMap;
pub struct Request {
parts: hyper::http::request::Parts,
body: Option<Incoming>,
}
impl Request {
pub fn is_get_or_head(&self) -> bool {
self.parts.method == Method::GET
|| self.parts.method == Method::HEAD
}
pub fn is_head(&self) -> bool {
self.parts.method == Method::HEAD
}
pub fn is_post(&self) -> bool {
self.parts.method == Method::POST
}
pub fn uri(&self) -> &Uri {
&self.parts.uri
}
pub fn body(self) -> Option<Incoming> {
self.body
}
pub fn headers(&self) -> &HeaderMap {
&self.parts.headers
}
pub fn is_api(&self) -> bool {
self.parts.uri.path().starts_with("/api/")
}
pub fn new(
parts: hyper::http::request::Parts,
body: Option<Incoming>
) -> Self {
Self { parts, body }
}
}