From be43605785732a92fba1f95e3337fa1f60f6f124 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Fri, 5 Mar 2021 22:42:55 +0100 Subject: pkgs/profpatsch/xdg-open: improve tool a bit --- pkgs/profpatsch/xdg-open/read-http.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'pkgs/profpatsch/xdg-open/read-http.rs') diff --git a/pkgs/profpatsch/xdg-open/read-http.rs b/pkgs/profpatsch/xdg-open/read-http.rs index 9fe8d6a9..3ec4c39a 100644 --- a/pkgs/profpatsch/xdg-open/read-http.rs +++ b/pkgs/profpatsch/xdg-open/read-http.rs @@ -25,7 +25,7 @@ fn main() -> std::io::Result<()> { Ok(_start_of_body) => { match resp.code { Some(code) => write_dict(code, resp.reason, resp.headers)?, - None => die(format!("no http status")) + None => die(format!("no http status in {:?}", resp)) } } }; @@ -41,11 +41,18 @@ fn write_dict<'buf>(code: u16, reason: Option<&'buf str>, headers: &mut [httpars http.push(("status-text", Box::new(U::Text(t.as_bytes())))) }; + let lowercase_headers = headers.iter_mut().map( + |httparse::Header { name, value }| + // lowercase the headers, since the standard doesn’t care + // and we want unique strings to match agains + (name.to_lowercase(), value) + ).collect::>(); + + http.push(("headers", Box::new(U::Record( - headers.iter_mut().map( - |httparse::Header { name, value }| - (*name, - Box::new(U::Binary(value))) + lowercase_headers.iter().map( + |(name, value)| + (name.as_str(), Box::new(U::Binary(value))) ).collect::>() )))); -- cgit 1.4.1