Skip to main content

rewrit_core/normalize/
http.rs

1use crate::normalize::{NormalizeContext, NormalizeError, Normalizer};
2use rewrit_model::{Effect, HttpCall, Observation};
3
4#[derive(Debug, Clone, Default)]
5pub struct HttpHeaderNormalizer;
6
7impl Normalizer for HttpHeaderNormalizer {
8    fn name(&self) -> &'static str {
9        "http_headers"
10    }
11
12    fn normalize(
13        &self,
14        mut observation: Observation,
15        _ctx: &NormalizeContext,
16    ) -> Result<Observation, NormalizeError> {
17        for effect in &mut observation.effects {
18            if let Effect::HttpCall(call) = effect {
19                normalize_call(call);
20            }
21        }
22        Ok(observation)
23    }
24}
25
26fn normalize_call(call: &mut HttpCall) {
27    call.request_headers = call
28        .request_headers
29        .iter()
30        .map(|(key, value)| (key.to_ascii_lowercase(), value.clone()))
31        .collect();
32    call.response_headers = call
33        .response_headers
34        .iter()
35        .map(|(key, value)| (key.to_ascii_lowercase(), value.clone()))
36        .collect();
37}