From f21a2524aa51500b166cc67015c76c9fc98b1480 Mon Sep 17 00:00:00 2001 From: Yannick Scherer Date: Tue, 3 Mar 2015 17:38:31 +0100 Subject: [PATCH] Add raw handler result to response metadata --- src/liberator/core.clj | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/liberator/core.clj b/src/liberator/core.clj index 8e90f5b..dfc24c8 100644 --- a/src/liberator/core.clj +++ b/src/liberator/core.clj @@ -126,6 +126,11 @@ {"Accept-Patch" (join "," ((:patch-content-types resource)))} {}))) +(defn handler-result->response + [{:keys [as-response]} context handler-result] + (when-let [response (as-response handler-result context)] + (vary-meta response assoc :liberator/value handler-result))) + (defn run-handler [name status message {:keys [resource request representation] :as context}] (let [context @@ -172,12 +177,10 @@ ;; override the status and headers. - (let [as-response (:as-response resource)] - (as-response - (if-let [handler (get resource (keyword name))] - (handler context) - (get context :message)) - context)))))] + (->> (if-let [handler (get resource (keyword name))] + (handler context) + (get context :message)) + (handler-result->response resource context)))))] (cond (or (= :options (:request-method request)) (= 405 (:status response))) (merge-with merge