Skip to main content

roas_http_validator/adapters/
rocket.rs

1//! `rocket::Request`.
2//!
3//! Rocket is the outlier: it shares nothing with the `http` crate — its
4//! `Method`, `Origin` and `HeaderMap` are its own — and its header map
5//! yields headers by value rather than by reference, so the names and
6//! values here are owned rather than borrowed. That is what
7//! [`RequestView`]'s `Cow` fields are for.
8
9use std::borrow::Cow;
10
11use crate::request::{RequestView, ToRequestView};
12
13impl ToRequestView for rocket::Request<'_> {
14    fn request_view(&self) -> RequestView<'_> {
15        let view = RequestView::new(self.method().as_str(), self.uri().path().as_str())
16            .with_headers(self.headers().iter().map(|header| {
17                (
18                    Cow::Owned(header.name().as_str().to_owned()),
19                    Cow::Owned(header.value().to_owned()),
20                )
21            }));
22        match self.uri().query() {
23            Some(query) => view.with_query(query.as_str().to_owned()),
24            None => view,
25        }
26    }
27}