ngrok/config/
headers.rs

1use std::collections::HashMap;
2
3use crate::internals::proto::Headers as HeaderProto;
4
5/// HTTP Headers to modify at the ngrok edge.
6#[derive(Clone, Default)]
7pub(crate) struct Headers {
8    /// Headers to add to requests or responses at the ngrok edge.
9    added: HashMap<String, String>,
10    /// Header names to remove from requests or responses at the ngrok edge.
11    removed: Vec<String>,
12}
13
14impl Headers {
15    pub(crate) fn add(&mut self, name: impl Into<String>, value: impl Into<String>) {
16        self.added.insert(name.into().to_lowercase(), value.into());
17    }
18    pub(crate) fn remove(&mut self, name: impl Into<String>) {
19        self.removed.push(name.into().to_lowercase());
20    }
21    pub(crate) fn has_entries(&self) -> bool {
22        !self.added.is_empty() || !self.removed.is_empty()
23    }
24}
25
26// transform into the wire protocol format
27impl From<Headers> for HeaderProto {
28    fn from(headers: Headers) -> Self {
29        HeaderProto {
30            add: headers
31                .added
32                .iter()
33                .map(|a| format!("{}:{}", a.0, a.1))
34                .collect(),
35            remove: headers.removed,
36            add_parsed: HashMap::new(), // unused in this context
37        }
38    }
39}