Permalink
Browse files

Added tests for header-seq, fixed nil header bug

  • Loading branch information...
1 parent d77d093 commit 771706ca761a8435f067201db9ded3b61abec6b0 @weavejester weavejester committed Jan 14, 2012
Showing with 19 additions and 2 deletions.
  1. +2 −2 ring-core/src/ring/util/request.clj
  2. +17 −0 ring-core/test/ring/util/test/request.clj
View
4 ring-core/src/ring/util/request.clj
@@ -7,8 +7,8 @@
"Returns seq of values for the specified header. Multiple values can be
encoded in one header key using a comma as a separator."
[request key]
- (-> (get-in request [:headers (name key)])
- (str/split #"\s*,\s*")))
+ (if-let [value (get-in request [:headers (name key)])]
+ (str/split value #"\s*,\s*")))
(defn- parse-attr-map [attrs]
(->> (map #(str/split % #"=") attrs)
View
17 ring-core/test/ring/util/test/request.clj
@@ -0,0 +1,17 @@
+(ns ring.util.test.request
+ (:use clojure.test
+ ring.util.request))
+
+(deftest test-header-seq
+ (are [r k hs] (= (header-seq r k) hs)
+ {:headers {"accept" "text/html, text/xml"}}
+ "accept"
+ ["text/html" "text/xml"]
+
+ {:headers {"content-type" "text/html"}}
+ "content-type"
+ ["text/html"]
+
+ {:headers {}}
+ "x-foo"
+ nil))

0 comments on commit 771706c

Please sign in to comment.