framework_cqrs_lib/cqrs/infra/helpers/
header_value.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use actix_web::http::header::HeaderValue;

use crate::cqrs::models::errors::{Error, ResultErr};

pub trait CanSanitizeHeader {
    fn sanitize_header(&self, name: String) -> ResultErr<(String, String)>;
}

impl CanSanitizeHeader for HeaderValue {
    fn sanitize_header(&self, name: String) -> ResultErr<(String, String)> {
        self.to_str()
            .map_err(|err| Error::Simple(err.to_string()))
            .map(|res| (name, res.to_string()))
    }
}