-
Notifications
You must be signed in to change notification settings - Fork 297
/
params.clj
46 lines (39 loc) · 1.43 KB
/
params.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
; Copyright 2013 Relevance, Inc.
; Copyright 2014-2019 Cognitect, Inc.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0)
; which can be found in the file epl-v10.html at the root of this distribution.
;
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
;
; You must not remove this notice, or any other, from this software.
(ns io.pedestal.http.params
(:require [io.pedestal.interceptor :as interceptor]))
(defn keywordize-keys
[x]
(if (map? x)
(persistent!
(reduce-kv
(fn [m k v]
(assoc! m
(if (string? k) (keyword k) k)
(keywordize-keys v)))
(transient {})
x))
x))
(defn keywordize-request-element
[element context]
(update-in context [:request element] keywordize-keys))
(def keywordize-request-params (partial keywordize-request-element :params))
(def keywordize-request-body-params (partial keywordize-request-element :body-params))
(def keyword-params
"Interceptor that converts the :params map to be keyed by keywords"
(interceptor/-interceptor
{:name ::keyword-params
:enter keywordize-request-params}))
(def keyword-body-params
"Interceptor that converts the :body-params map to be keyed by keywords"
(interceptor/-interceptor
{:name ::keyword-body-params
:enter keywordize-request-body-params}))