Created
September 14, 2020 23:35
-
-
Save luavixen/5c07264f487db8e020715a845f7967f9 to your computer and use it in GitHub Desktop.
Request guard for https://rocket.rs/ that allows you to access the raw request.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ops::Deref; | |
use rocket::request::{Request, FromRequest, Outcome}; | |
pub struct RawRequest<'a, 'r> (pub &'a Request<'r>); | |
impl<'a, 'r> Deref for RawRequest<'a, 'r> { | |
type Target = Request<'r>; | |
fn deref(&self) -> &Self::Target { | |
self.0 | |
} | |
} | |
impl<'a, 'r> FromRequest<'a, 'r> for RawRequest<'a, 'r> { | |
type Error = (); | |
fn from_request(request: &'a Request<'r>) -> Outcome<Self, Self::Error> { | |
Outcome::Success(RawRequest(request)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment