From d682d9e546f12b9a13363e49b96975503d5d21a5 Mon Sep 17 00:00:00 2001 From: onionpancakes <639985+onionpancakes@users.noreply.github.com> Date: Tue, 21 Nov 2023 22:52:12 -0800 Subject: [PATCH] impl ILookup for response proxy --- src/dev/onionpancakes/hop/response.clj | 7 +++++++ test/dev/onionpancakes/hop/tests/test_response.clj | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/dev/onionpancakes/hop/response.clj b/src/dev/onionpancakes/hop/response.clj index 4bf6532..21d2936 100644 --- a/src/dev/onionpancakes/hop/response.clj +++ b/src/dev/onionpancakes/hop/response.clj @@ -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.))) diff --git a/test/dev/onionpancakes/hop/tests/test_response.clj b/test/dev/onionpancakes/hop/tests/test_response.clj index 3206407..70e2336 100644 --- a/test/dev/onionpancakes/hop/tests/test_response.clj +++ b/test/dev/onionpancakes/hop/tests/test_response.clj @@ -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