Files
tbd/test/tbd/test_util.clj
ajet 31e03d552b
CI / Test + coverage (push) Successful in 34s
handle formats
2026-09-19 07:49:15 -09:00

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)))