Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(volo-http): support extract HeaderMap #437

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions volo-http/src/server/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{convert::Infallible, marker::PhantomData};
use bytes::Bytes;
use faststr::FastStr;
use futures_util::Future;
use http::{header, request::Parts, Method, Request, Uri};
use http::{header, request::Parts, HeaderMap, Method, Request, Uri};
use http_body::Body;
use http_body_util::BodyExt;
use hyper::body::Incoming;
Expand Down Expand Up @@ -106,7 +106,7 @@ impl FromContext for Uri {
async fn from_context(
_cx: &mut ServerContext,
parts: &mut Parts,
) -> Result<Uri, Self::Rejection> {
) -> Result<Self, Self::Rejection> {
Ok(parts.uri.to_owned())
}
}
Expand All @@ -117,11 +117,22 @@ impl FromContext for Method {
async fn from_context(
_cx: &mut ServerContext,
parts: &mut Parts,
) -> Result<Method, Self::Rejection> {
) -> Result<Self, Self::Rejection> {
Ok(parts.method.to_owned())
}
}

impl FromContext for HeaderMap {
type Rejection = Infallible;

async fn from_context(
_cx: &mut ServerContext,
parts: &mut Parts,
) -> Result<Self, Self::Rejection> {
Ok(parts.headers.to_owned())
}
}

#[cfg(feature = "query")]
#[cfg_attr(docsrs, doc(cfg(feature = "query")))]
impl<T> FromContext for Query<T>
Expand Down
Loading