From ba35cdd90b4da26e2ae3421ec6c203035e8b3699 Mon Sep 17 00:00:00 2001 From: onionpancakes <639985+onionpancakes@users.noreply.github.com> Date: Mon, 20 Nov 2023 20:00:00 -0800 Subject: [PATCH] replaced HeaderValue Coll impl with Indexed and Seqable --- src/dev/onionpancakes/hop/request.clj | 16 ++++++++++++---- .../onionpancakes/hop/tests/test_request.clj | 18 ++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/dev/onionpancakes/hop/request.clj b/src/dev/onionpancakes/hop/request.clj index b955503..566d4d3 100644 --- a/src/dev/onionpancakes/hop/request.clj +++ b/src/dev/onionpancakes/hop/request.clj @@ -57,10 +57,17 @@ ;; Headers (extend-protocol HeaderValue - java.util.Collection + clojure.lang.Indexed (add-header-to-request-builder [this builder header-name] - (let [add-header-rf #(add-header-to-request-builder %2 % header-name)] - (reduce add-header-rf builder this))) + (loop [i 0 cnt (count this)] + (when (< i cnt) + (-> (nth this i) + (add-header-to-request-builder builder header-name)) + (recur (inc i) cnt)))) + clojure.lang.Seqable + (add-header-to-request-builder [this builder header-name] + (doseq [value this] + (add-header-to-request-builder value builder header-name))) String (add-header-to-request-builder [this builder header-name] (.header ^HttpRequest$Builder builder header-name this)) @@ -72,7 +79,8 @@ (defn add-request-builder-header [builder k value] - (add-header-to-request-builder value builder (name k))) + (add-header-to-request-builder value builder (name k)) + builder) (defn add-request-builder-headers ^HttpRequest$Builder diff --git a/test/dev/onionpancakes/hop/tests/test_request.clj b/test/dev/onionpancakes/hop/tests/test_request.clj index 327870c..02c0fa7 100644 --- a/test/dev/onionpancakes/hop/tests/test_request.clj +++ b/test/dev/onionpancakes/hop/tests/test_request.clj @@ -44,14 +44,16 @@ (= (.map (.headers obj)) expected)) nil {} {} {} - {"Foo" nil} {} - {"Foo" []} {} - {:Foo [nil]} {} - {"Foo" "Bar"} {"Foo" ["Bar"]} - {"Foo" ["Bar"]} {"Foo" ["Bar"]} - {:Foo ["Bar"]} {"Foo" ["Bar"]} - {"Foo" 0} {"Foo" ["0"]} - {"Foo" [0]} {"Foo" ["0"]} + {"foo" nil} {} + {"foo" []} {} + {:foo [nil]} {} + {"foo" "bar"} {"foo" ["bar"]} + {"foo" ["bar"]} {"foo" ["bar"]} + {:foo ["bar"]} {"foo" ["bar"]} + {:foo ["bar"]} {"foo" ["bar"]} + {:foo '("bar")} {"foo" ["bar"]} + {"foo" 0} {"foo" ["0"]} + {"foo" [0]} {"foo" ["0"]} ;; Mixed {:Foo ["Bar" "Baz"] :Qux "Mux"} {"Foo" ["Bar" "Baz"]