Skip to main content

roas_http_validator/adapters/
poem.rs

1//! `poem::Request`.
2//!
3//! poem keeps its own request type but builds it on the `http` crate's
4//! parts, so the conversion is the same shape as the `http` adapter's.
5
6use std::borrow::Cow;
7
8use crate::request::{RequestView, ToRequestView};
9
10impl ToRequestView for poem::Request {
11    fn request_view(&self) -> RequestView<'_> {
12        let view = RequestView::new(self.method().as_str(), self.uri().path()).with_headers(
13            self.headers().iter().map(|(name, value)| {
14                let value = match value.to_str() {
15                    Ok(text) => Cow::Borrowed(text),
16                    Err(_) => Cow::Owned(String::from_utf8_lossy(value.as_bytes()).into_owned()),
17                };
18                (Cow::Borrowed(name.as_str()), value)
19            }),
20        );
21        match self.uri().query() {
22            Some(query) => view.with_query(query),
23            None => view,
24        }
25    }
26}