Skip to main content

roas_http_validator/adapters/
salvo.rs

1//! `salvo_core::http::Request`.
2//!
3//! Salvo wraps hyper's parts in a type of its own — `Request::from_hyper`
4//! is how one is built — and exposes them under the same names, so the
5//! head converts exactly as the `http` adapter's does.
6
7use std::borrow::Cow;
8
9use crate::request::{RequestView, ToRequestView};
10
11impl ToRequestView for salvo_core::http::Request {
12    fn request_view(&self) -> RequestView<'_> {
13        let view = RequestView::new(self.method().as_str(), self.uri().path()).with_headers(
14            self.headers().iter().map(|(name, value)| {
15                let value = match value.to_str() {
16                    Ok(text) => Cow::Borrowed(text),
17                    Err(_) => Cow::Owned(String::from_utf8_lossy(value.as_bytes()).into_owned()),
18                };
19                (Cow::Borrowed(name.as_str()), value)
20            }),
21        );
22        match self.uri().query() {
23            Some(query) => view.with_query(query),
24            None => view,
25        }
26    }
27}