Permalink
Browse files

Added the response? function

  • Loading branch information...
1 parent 41545ea commit 63ccb942d9daa7791b7162770bbdeb2eccb54fb5 @weavejester weavejester committed Feb 12, 2012
Showing with 13 additions and 0 deletions.
  1. +7 −0 ring-core/src/ring/util/response.clj
  2. +6 −0 ring-core/test/ring/util/test/response.clj
View
7 ring-core/src/ring/util/response.clj
@@ -128,3 +128,10 @@
wrap-cookies middleware."
[resp name value & [opts]]
(assoc-in resp [:cookies name] (merge {:value value} opts)))
+
+(defn response?
+ "True if the supplied value is a valid response map."
+ [resp]
+ (and (map? resp)
+ (integer? (:status resp))
+ (map? (:headers resp))))
View
6 ring-core/test/ring/util/test/response.clj
@@ -32,6 +32,12 @@
(is (= {:status 200 :headers {"X-Foo" "Bar"}}
(header {:status 200 :headers {}} "X-Foo" "Bar"))))
+(deftest test-response?
+ (is (response? {:status 200, :headers {}}))
+ (is (response? {:status 200, :headers {}, :body "Foo"}))
+ (is (not (response? {})))
+ (is (not (response? {:users []}))))
+
(defmacro with-classloader
"Temporarily replaces the current context classloader with one that
includes everything in dir"

0 comments on commit 63ccb94

Please sign in to comment.