Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added tests for accept, fixed nil header bug

  • Loading branch information...
commit 3b8ad977fe8b6cc96d9839aa7c520a1c654d1f6c 1 parent 1d75558
@weavejester weavejester authored
View
8 ring-core/src/ring/util/request.clj
@@ -22,13 +22,13 @@
(assoc :value value))))
(defn accept
- "Parse the accept header and returns an ordered seq of maps for each media
- type. Each map will contain at least a :value and a :q key.
+ "Parse the accept header and returns a seq of maps for each media type.
+ Each map will contain at least a :value and a :q key.
e.g. (accept {:headers {\"accept\": \"text/html, text/xml;q=0.8\"})
=> ({:value \"text/html\", :q 1.0}
{:value \"text/xml\", :q 0.8})"
[request]
- (->> (header-seq request "accept")
- (map parse-accept-value)))
+ (if-let [values (header-seq request "accept")]
+ (map parse-accept-value values)))
View
11 ring-core/test/ring/util/test/request.clj
@@ -7,3 +7,14 @@
"accept" "text/html, text/xml" ["text/html" "text/xml"]
"content-type" "text/html" ["text/html"]
"x-foo" nil nil))
+
+(deftest test-accept
+ (are [a b] (= (accept {:headers {"accept" a}}) b)
+ "text/html, text/xml"
+ [{:value "text/html" :q 1.0} {:value "text/xml" :q 1.0}]
+ "text/html"
+ [{:value "text/html" :q 1.0}]
+ "text/xml;q=0.5, application/json"
+ [{:value "text/xml" :q 0.5} {:value "application/json" :q 1.0}]
+ nil
+ nil))
Please sign in to comment.
Something went wrong with that request. Please try again.