use crate::RequestContext;
use crate::body::OptionReqBody;
use crate::extract::from_request::FromRequest;
use http::{HeaderMap, Method};
use micro_http::protocol::{ParseError, RequestHeader};
impl FromRequest for Method {
type Output<'any> = Method;
type Error = ParseError;
async fn from_request(req: &RequestContext<'_, '_>, _body: OptionReqBody) -> Result<Self::Output<'static>, Self::Error> {
Ok(req.method().clone())
}
}
impl FromRequest for &Method {
type Output<'r> = &'r Method;
type Error = ParseError;
async fn from_request<'r>(req: &'r RequestContext<'_, '_>, _body: OptionReqBody) -> Result<Self::Output<'r>, Self::Error> {
Ok(req.method())
}
}
impl FromRequest for &RequestHeader {
type Output<'r> = &'r RequestHeader;
type Error = ParseError;
async fn from_request<'r>(req: &'r RequestContext<'_, '_>, _body: OptionReqBody) -> Result<Self::Output<'r>, Self::Error> {
Ok(req.request_header())
}
}
impl FromRequest for &HeaderMap {
type Output<'r> = &'r HeaderMap;
type Error = ParseError;
async fn from_request<'r>(req: &'r RequestContext<'_, '_>, _body: OptionReqBody) -> Result<Self::Output<'r>, Self::Error> {
Ok(req.headers())
}
}
impl FromRequest for HeaderMap {
type Output<'any> = HeaderMap;
type Error = ParseError;
async fn from_request(req: &RequestContext<'_, '_>, _body: OptionReqBody) -> Result<Self::Output<'static>, Self::Error> {
Ok(req.headers().clone())
}
}