Fork me on GitHub
#reitit
<
2018-11-19
>
valerauko04:11:05

remind me what's the correct way for negotiating html responses please?

valerauko04:11:20

i made a custom muuntaja formatter for text/html

valerauko04:11:42

(def negotiator
  (muuntaja/create
    (assoc-in muuntaja/default-options
              [:formats "text/html"]
              (html-format/format))))

valerauko04:11:46

mounted it on my routes as

valerauko04:11:49

{:data {:muuntaja negotiator
              :middleware [format-middleware
                           require-tmb-session]}})

valerauko04:11:18

the :muuntaja/response key is correctly set to {:format "text/html", :charset "utf-8", :raw-format "text/html"} but it's not injected in the response map

valerauko04:11:26

so the response goes out as application/octet-stream

valerauko04:11:34

am i missing something?

valerauko04:11:29

i thought format-middleware should handle the Content-type header if missing

ikitommi05:11:22

@vale what is your endpoint returning as :body? by default, only collection bodies are encoded. This is quite lame imo and there is an issue for it: https://github.com/metosin/reitit/issues/122

valerauko05:11:51

i'm returning string :body

ikitommi05:11:19

a) you could override that default in the negotiator b) switch-case on the negotiated content-type in a custom mw c) let't resolve the issue

valerauko05:11:37

for an immediate solution, could you point me to how to override said default?

valerauko05:11:24

currently i have a format an encoder and a decoder defined for the negotiator

ikitommi05:11:11

@vale set the [:http :encode-response-body?] to (constantly true) in Muuntaja options

💯 4
👍 4
valerauko05:11:21

thanks, that did the trick!

valerauko05:11:29

gonna look at that issue the weekend!

👍 4