2018-10-03 20:48:25 +02:00
|
|
|
use rocket::request::{self, FromRequest, Request};
|
2018-11-24 12:44:17 +01:00
|
|
|
use rocket::{
|
|
|
|
http::{Header, HeaderMap},
|
|
|
|
Outcome,
|
|
|
|
};
|
2018-10-03 20:48:25 +02:00
|
|
|
|
|
|
|
pub struct Headers<'r>(pub HeaderMap<'r>);
|
|
|
|
|
|
|
|
impl<'a, 'r> FromRequest<'a, 'r> for Headers<'r> {
|
|
|
|
type Error = ();
|
|
|
|
|
|
|
|
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, ()> {
|
|
|
|
let mut headers = HeaderMap::new();
|
|
|
|
for header in request.headers().clone().into_iter() {
|
|
|
|
headers.add(header);
|
|
|
|
}
|
2018-10-10 21:10:43 +02:00
|
|
|
let ori = request.uri();
|
|
|
|
let uri = if let Some(query) = ori.query() {
|
|
|
|
format!("{}?{}", ori.path(), query)
|
|
|
|
} else {
|
|
|
|
ori.path().to_owned()
|
|
|
|
};
|
2018-11-24 12:44:17 +01:00
|
|
|
headers.add(Header::new(
|
|
|
|
"(request-target)",
|
|
|
|
format!("{} {}", request.method().as_str().to_lowercase(), uri),
|
|
|
|
));
|
2018-10-03 20:48:25 +02:00
|
|
|
Outcome::Success(Headers(headers))
|
|
|
|
}
|
|
|
|
}
|