roas_http_validator/adapters/
salvo.rs1use 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}