Skip to content

Commit

Permalink
Allow keyword headers (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurC committed Jan 15, 2021
1 parent 1638957 commit 33bfad1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/babashka/curl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@
(case method
:head ["--head"]
["--request" (-> method name str/upper-case)]))
headers (:headers opts)
headers (loop [headers* (transient [])
kvs (seq headers)]
(if kvs
(let [[k v] (first kvs)]
(recur (reduce conj! headers* ["-H" (str k ": " v)]) (next kvs)))
(persistent! headers*)))
headers (into [] (mapcat (fn [[k v]] ["-H" (str (name k) ": " v)])) (:headers opts))
accept-header (accept-header opts)
form-params (when-let [form-params (:form-params opts)]
(loop [params* (transient [])
Expand Down
8 changes: 8 additions & 0 deletions test/babashka/curl_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,11 @@
(-> (curl/get "https://api.stackexchange.com/2.2/sites"
{:compressed false})
:body (json/parse-string true) :items))))

(deftest header-with-keyword-key-test
(is (= 200
(-> (curl/get "https://httpstat.us/200"
{:headers {:accept "application/json"}})
:body
(json/parse-string true)
:code))))

0 comments on commit 33bfad1

Please sign in to comment.