diff --git a/src/dev/onionpancakes/hop/headers.clj b/src/dev/onionpancakes/hop/headers.clj index 0893945..02117bd 100644 --- a/src/dev/onionpancakes/hop/headers.clj +++ b/src/dev/onionpancakes/hop/headers.clj @@ -51,9 +51,17 @@ ;; Headers -(def headers-map-xf +(def to-map-xf (map (juxt key (comp vec val)))) -(defn headers-map +(defn to-map [^HttpHeaders headers] (into {} headers-map-xf (.map headers))) + +(def from-map-bi-predicate + (reify java.util.function.BiPredicate + (test [_ _ _] true))) + +(defn from-map + [m] + (HttpHeaders/of m from-map-bi-predicate)) diff --git a/src/dev/onionpancakes/hop/response.clj b/src/dev/onionpancakes/hop/response.clj index fa3ebe3..0023faf 100644 --- a/src/dev/onionpancakes/hop/response.clj +++ b/src/dev/onionpancakes/hop/response.clj @@ -43,12 +43,12 @@ :media-type (.. response (headers) (firstValue "content-type") - (map util/parse-media-type-function) + (map h/parse-media-type-function) (orElse nil)) :character-encoding (.. response (headers) (firstValue "content-type") - (map util/parse-character-encoding-function) + (map h/parse-character-encoding-function) (orElse nil)) :ssl-session (.. response (sslSession) (orElse nil)) :previous-response (.. response @@ -72,7 +72,7 @@ (defn response-proxy [^HttpResponse response] - (let [headers (delay (h/headers-map (.headers response)))] + (let [headers (delay (h/to-map (.headers response)))] (ResponseProxy. response headers))) (def ^java.util.function.Function response-proxy-function diff --git a/test/dev/onionpancakes/hop/test_response.clj b/test/dev/onionpancakes/hop/test_response.clj index 0b5997d..2f70548 100644 --- a/test/dev/onionpancakes/hop/test_response.clj +++ b/test/dev/onionpancakes/hop/test_response.clj @@ -1,5 +1,6 @@ (ns dev.onionpancakes.hop.test-response (:require [clojure.test :refer [deftest is are]] + [dev.onionpancakes.hop.headers :as headers] [dev.onionpancakes.hop.request :as request] [dev.onionpancakes.hop.response :as response]) (:import [java.net.http HttpResponse HttpHeaders HttpRequest @@ -12,10 +13,8 @@ (body [this] "Body") (headers [this] - (-> {"content-encoding" ["gzip"] - "content-type" ["text/plain;charset=utf-8"]} - (HttpHeaders/of (reify BiPredicate - (test [_ _ _] true))))) + (headers/from-map {"content-encoding" ["gzip"] + "content-type" ["text/plain;charset=utf-8"]})) (previousResponse [this] (Optional/ofNullable nil)) (request [this]