;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>

(ns uxbox.frontend.core)

(defmulti -handler
  (comp (juxt :type :dest) second vector))

;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>

(ns uxbox.frontend.core
  (:require [catacumba.impl.handlers :as cih]
            [catacumba.serializers :as csz])
  (:import ratpack.handling.Context
           ratpack.http.Response
           ratpack.http.MutableHeaders))


(deftype Rsp [data]
  cih/ISend
  (-send [_ ctx]
    (let [^Response response (.getResponse ^Context ctx)
          ^MutableHeaders headers (.getHeaders response)]
      (.set headers "content-type" "application/transit+json")
      (cih/-send (csz/encode data :transit+json) ctx))))

(defn rsp
  "A shortcut for create a response instance."
  [data]
  (Rsp. data))

Add rsp type that properly implements catacumba protocols.
Add rsp type that properly implements catacumba protocols.

This is a compatibility layer for future support of
content negotiation on catacumba.

uxbox/uxbox-backend,uxbox/uxbox-backend