Skip to content

Commit

Permalink
impl ILookup for response proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
onionpancakes committed Nov 22, 2023
1 parent ba35cdd commit d682d9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/dev/onionpancakes/hop/response.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
:ssl-session :previous-response])

(deftype ResponseProxy [^HttpResponse response headers]
clojure.lang.ILookup
(valAt [this k]
(.get this k))
(valAt [this k not-found]
(if (.containsKey this k)
(.get this k)
not-found))
java.util.Map
(clear [this]
(throw (UnsupportedOperationException.)))
Expand Down
3 changes: 3 additions & 0 deletions test/dev/onionpancakes/hop/tests/test_response.clj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
:previous-response nil
:not-a-key nil))

(deftest test-response-proxy-lookup-not-found
(is (= (get example-response-proxy ::foo :not-found) :not-found)))

(deftest test-response-proxy-clj
(are [value expected] (= value expected)
example-response-proxy example-response-map
Expand Down

0 comments on commit d682d9e

Please sign in to comment.