15 lines
601 B
Clojure
15 lines
601 B
Clojure
(ns tbd.test-util
|
|
(:require [clojure.string :as str]
|
|
[muuntaja.core :as m]
|
|
[tbd.http :as http]))
|
|
|
|
(defn decode-body
|
|
"Reads a response's body back into data by the response's own Content-Type (JSON, EDN or
|
|
Transit). Bodies that aren't one of those, like text/plain, are left alone."
|
|
[resp]
|
|
(let [content-type (get-in resp [:headers "Content-Type"] "")
|
|
body (:body resp)]
|
|
(if (and body (not (string? body)) (re-find #"json|edn|transit" content-type))
|
|
(update resp :body #(m/decode http/muuntaja (first (str/split content-type #";")) %))
|
|
resp)))
|