Skip to content

Instantly share code, notes, and snippets.

@luavixen
Created September 14, 2020 23:35
Show Gist options
  • Save luavixen/5c07264f487db8e020715a845f7967f9 to your computer and use it in GitHub Desktop.
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.
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