clj-http
clj-http copied to clipboard
`clj-http.headers.HeaderMap` is not fully compatible with normal Clojure maps
Maps returned by header-map (HeaderMap instance) are not fully compatible with normal Clojure maps. These maps are part of the clj-http reponse data.
Not sure what if anything should be done to fix this.
=>
(clojure.set/rename-keys (into (clj-http.headers/header-map) {"Foo" "Bar"})
{"Foo" :foo})
{"Foo" "Bar"}
=>
(clojure.set/rename-keys (into {} {"Foo" "Bar"})
{"Foo" :foo})
{:foo "Bar"}
- https://github.com/dakrone/clj-http/blob/3.x/src/clj_http/headers.clj#L105
- https://github.com/dakrone/clj-http/blob/3.x/src/clj_http/headers.clj#L133
Hmm okay, we need to figure out what rename-keys uses that the HeaderMap needs to implement in order to get it to work.
rename-keys uses assoc internally. assoc behaves like this: HeaderMap converts keyword keys to Pascal cased string keys. So maybe this is just a feature of HeaderMap.
(require 'clj-http.headers)
(def a (into (clj-http.headers/header-map) {"Foo" "Bar"}) )
(assoc a :foo "baz")
=> {"Foo" "baz"}
(assoc a :quux-xyz "baz")
=> {"Foo" "Bar", "Quux-Xyz" "baz"}
(assoc a "foob" "baz")
=> {"Foo" "Bar", "foob" "baz"}
Anyways, you can use (into {} ...) to convert HeaderMap to normal Clojure data structure.
(def a (into (clj-http.headers/header-map) {"Foo" "Bar"}) )
(def b (into {} a))
(clojure.set/rename-keys b {"Foo" :foo})
=> {:foo "Bar"}