Skip to content
Snippets Groups Projects
Unverified Commit b0c471ef authored by Alexander Solovyov's avatar Alexander Solovyov Committed by GitHub
Browse files

ring-json already supports converting stuff to keywords (#39416)

parent 83bf2554
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@
[ring.core.protocols :as ring.protocols]
[ring.middleware.cookies :refer [wrap-cookies]]
[ring.middleware.gzip :refer [wrap-gzip]]
[ring.middleware.json :as ring.json]
[ring.middleware.keyword-params :refer [wrap-keyword-params]]
[ring.middleware.params :refer [wrap-params]]))
......@@ -46,7 +47,7 @@
#'mw.log/log-api-call
#'mw.browser-cookie/ensure-browser-id-cookie ; add cookie to identify browser; add `:browser-id` to the request
#'mw.security/add-security-headers ; Add HTTP headers to API responses to prevent them from being cached
#'mw.json/wrap-json-body ; extracts json POST body and makes it avaliable on request
#(ring.json/wrap-json-body % {:keywords? true}) ; extracts json POST body and makes it available on request
#'mw.offset-paging/handle-paging ; binds per-request parameters to handle paging
#'mw.json/wrap-streamed-json-response ; middleware to automatically serialize suitable objects as JSON in responses
#'wrap-keyword-params ; converts string keys in :params to keyword keys
......
......@@ -5,7 +5,6 @@
[cheshire.factory]
[cheshire.generate :as json.generate]
[metabase.util.date-2 :as u.date]
[ring.middleware.json :as ring.json]
[ring.util.io :as rui]
[ring.util.response :as response])
(:import
......@@ -50,25 +49,6 @@
(write-string! json-generator (apply str "0x" (for [b (take 4 byte-ar)]
(format "%02X" b))))))
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | Parsing JSON Requests |
;;; +----------------------------------------------------------------------------------------------------------------+
(defn wrap-json-body
"Middleware that parses JSON in the body of a request. (This is basically a copy of `ring-json-middleware`, but
tweaked to handle async-style calls.)"
;; TODO - we should really just fork ring-json-middleware and put these changes in the fork, or submit this as a PR
[handler]
(fn
[request respond raise]
(if-let [[valid? json] (#'ring.json/read-json request {:keywords? true})]
(if valid?
(handler (assoc request :body json) respond raise)
(respond ring.json/default-malformed-response))
(handler request respond raise))))
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | Streaming JSON Responses |
;;; +----------------------------------------------------------------------------------------------------------------+
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment