diff options
Diffstat (limited to 'src/encoding/headermap.rs')
-rw-r--r-- | src/encoding/headermap.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/encoding/headermap.rs b/src/encoding/headermap.rs index 65ef8d2..5d1fa0a 100644 --- a/src/encoding/headermap.rs +++ b/src/encoding/headermap.rs @@ -1,5 +1,5 @@ use super::headers::Header; -use anyhow::Result; +use anyhow::{anyhow, Result}; use std::fmt::Display; #[derive(Debug, Clone)] @@ -38,6 +38,17 @@ impl Display for HeaderMap { Ok(()) } } +impl HeaderMap { + pub fn parse<'a>(lines: &mut impl Iterator<Item = &'a str>) -> Result<Self> { + let mut headers = HeaderMap::new(); + for line in lines { + // TODO multiline values + let (key, value) = line.split_once(":").ok_or(anyhow!("header malformed"))?; + headers.insert_raw(key.trim().to_string(), value.trim().to_string()) + } + Ok(headers) + } +} impl FromIterator<(String, String)> for HeaderMap { fn from_iter<T: IntoIterator<Item = (String, String)>>(iter: T) -> Self { |