Clojure client: use case-insensitive checking on JSON MIME

This commit is contained in:
xhh 2015-12-09 22:55:49 +08:00
parent 7642314b20
commit 63092b8923
3 changed files with 6 additions and 4 deletions

View File

@ -174,7 +174,7 @@
[mime]
(if mime
(or (= :json mime)
(re-matches #"application/json(;.*)?" (name mime)))))
(re-matches #"(?i)application/json(;.*)?" (name mime)))))
(defn json-preferred-mime
"Choose a MIME from the given MIMEs with JSON preferred,

View File

@ -174,7 +174,7 @@
[mime]
(if mime
(or (= :json mime)
(re-matches #"application/json(;.*)?" (name mime)))))
(re-matches #"(?i)application/json(;.*)?" (name mime)))))
(defn json-preferred-mime
"Choose a MIME from the given MIMEs with JSON preferred,

View File

@ -151,10 +151,12 @@
(is (= expected (boolean (json-mime? mime))))
:json true
"application/json" true
"APPLICATION/JSON" true
"application/json; charset=utf8" true
nil false
:xml false
"application/pdf" false))
"application/pdf" false
"application/jsonp" false))
(deftest test-json-preferred-mime
(are [mimes expected]
@ -177,4 +179,4 @@
"{\"aa\": 1, \"bb\": \"2\"}" "application/json" {:aa 1 :bb "2"}
"[1, \"2\"]" "application/json; charset=UTF8" [1 "2"]
"{invalid json}" "application/json" "{invalid json}"
"plain text" "text/plain" "plain text"))
"plain text" "text/plain" "plain text"))