about summary refs log tree commit diff
path: root/pkgs/profpatsch/xdg-open/read-http.rs
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2021-03-05 22:42:55 +0100
committerProfpatsch <mail@profpatsch.de>2021-03-05 22:56:29 +0100
commitbe43605785732a92fba1f95e3337fa1f60f6f124 (patch)
treef6da9bb97cab3d41d284fe7b01f09b771d13a92c /pkgs/profpatsch/xdg-open/read-http.rs
parent009cb2bab9777e87d362584bb5992ad90631568e (diff)
pkgs/profpatsch/xdg-open: improve tool a bit
Diffstat (limited to 'pkgs/profpatsch/xdg-open/read-http.rs')
-rw-r--r--pkgs/profpatsch/xdg-open/read-http.rs17
1 files changed, 12 insertions, 5 deletions
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::<Vec<_>>();
+
+
     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::<Vec<_>>()
     ))));