Implement FromRequest for Accept.

This commit is contained in:
Sergio Benitez 2017-03-29 04:21:18 -07:00
parent c58ca894b7
commit b102a6a497
1 changed files with 12 additions and 1 deletions

View File

@ -5,7 +5,7 @@ use outcome::{self, IntoOutcome};
use request::Request; use request::Request;
use outcome::Outcome::*; use outcome::Outcome::*;
use http::{Status, ContentType, Method, Cookies, Session}; use http::{Status, ContentType, Accept, Method, Cookies, Session};
use http::uri::URI; use http::uri::URI;
/// Type alias for the `Outcome` of a `FromRequest` conversion. /// Type alias for the `Outcome` of a `FromRequest` conversion.
@ -220,6 +220,17 @@ impl<'a, 'r> FromRequest<'a, 'r> for Session<'a> {
} }
} }
impl<'a, 'r> FromRequest<'a, 'r> for Accept {
type Error = ();
fn from_request(request: &'a Request<'r>) -> Outcome<Self, Self::Error> {
match request.accept() {
Some(accept) => Success(accept),
None => Forward(())
}
}
}
impl<'a, 'r> FromRequest<'a, 'r> for ContentType { impl<'a, 'r> FromRequest<'a, 'r> for ContentType {
type Error = (); type Error = ();