(defn- parse-content-type
"Parse `s` as an RFC 2616 media type."
[s]
(when-let [m (re-matches #"\s*(([^/]+)/([^ ;]+))\s*(\s*;.*)?" (str s))]
{:content-type (keyword (nth m 1))
:content-type-params
(->> (clojure.string/split (str (nth m 4)) #"\s*;\s*")
(remove clojure.string/blank?)
(map #(clojure.string/split % #"="))
(map (fn [[k v]] [(keyword (clojure.string/lower-case k)) (clojure.string/trim v)]))
(into {}))}))
Some other options:
1) Wrap w/ a try/catch and let coerce-response-body just hit the default defmethod
2) Wrap with a try/catch and throw a specific exception about invalid content-type header
3) Attempt to parse as much as possible such as changing this line to what's below. This will cause the body to be parsed as json still but will ignore the encoding since it couldn't be parsed.
(map (fn [[k v]] (when (and k v) [(keyword (clojure.string/lower-case k)) (clojure.string/trim v)])))
I'm fine closing this one as I could go either way on if this is a real issue or not or what the debatable expected behavior should be.
One of our services was accidentally sending back
application/json; charset: utf8
instead ofapplication/json; charset=utf8
which causes hato to fail:Some other options:
1) Wrap w/ a try/catch and let
coerce-response-body
just hit the default defmethod 2) Wrap with a try/catch and throw a specific exception about invalid content-type header 3) Attempt to parse as much as possible such as changing this line to what's below. This will cause the body to be parsed as json still but will ignore the encoding since it couldn't be parsed.(map (fn [[k v]] (when (and k v) [(keyword (clojure.string/lower-case k)) (clojure.string/trim v)])))