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

Implement requiements from #1067 by importing typed headers from 'headers' … #2867

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
#1067: Fix whitespace
jespersm committed Sep 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 368288ef064403c9db25787977a3a7583a716d08
17 changes: 10 additions & 7 deletions core/lib/src/request/from_request_headers.rs
Original file line number Diff line number Diff line change
@@ -11,16 +11,18 @@ macro_rules! typed_headers_from_request {
#[rocket::async_trait]
impl<'r> FromRequest<'r> for $name {
type Error = headers::Error;
async fn from_request(req: &'r Request<'_>) -> crate::request::Outcome<Self, Self::Error> {
async fn from_request(req: &'r Request<'_>) ->
crate::request::Outcome<Self, Self::Error> {
req.headers().get($name::name().as_str()).next().or_forward(Status::NotFound)
.and_then(|h| HHeaderValue::from_str(h).or_error(Status::BadRequest))
.map_error(|(s, _)| (s, headers::Error::invalid()))
.and_then(|h| $name::decode(&mut std::iter::once(&h)).or_forward(Status::BadRequest))
.and_then(|h| $name::decode(&mut std::iter::once(&h))
.or_forward(Status::BadRequest))
}
}
)*)
}

macro_rules! generic_typed_headers_from_request {
($($name:ident<$bound:ident>),*) => ($(
pub use crate::http::$name;
@@ -29,15 +31,17 @@ macro_rules! generic_typed_headers_from_request {
impl<'r, T1: 'static + $bound> FromRequest<'r> for $name<T1> {
type Error = headers::Error;
async fn from_request(req: &'r Request<'_>) -> crate::request::Outcome<Self, Self::Error> {
req.headers().get($name::<T1>::name().as_str()).next().or_forward(Status::NotFound)
req.headers().get($name::<T1>::name().as_str()).next()
.or_forward(Status::NotFound)
.and_then(|h| HHeaderValue::from_str(h).or_error(Status::BadRequest))
.map_error(|(s, _)| (s, headers::Error::invalid()))
.and_then(|h| $name::decode(&mut std::iter::once(&h)).or_forward(Status::BadRequest))
.and_then(|h| $name::decode(&mut std::iter::once(&h))
.or_forward(Status::BadRequest))
}
}
)*)
}

// The following headers from 'headers' 0.4 are not imported, since they are
// provided by other Rocket features.

@@ -100,4 +104,3 @@ generic_typed_headers_from_request! {
Authorization<Credentials>, // Authorization header, defined in RFC7235
ProxyAuthorization<Credentials> // Proxy-Authorization header, defined in RFC7235
}