Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short-circuit nested-params when already applied or empty #236

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ring-core/src/ring/middleware/nested_params.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@
See: wrap-nested-params."
{:arglists '([request] [request options])
:added "1.2"}
[request & [opts]]
[{:keys [params] :as request} & [opts]]
(let [parse (:key-parser opts parse-nested-keys)]
(update-in request [:params] nest-params parse)))
(if (or (empty? params) (-> params meta :nested-params))
request
(assoc request :params ^:nested-params (nest-params params parse)))))

(defn wrap-nested-params
"Middleware to converts a flat map of parameters into a nested map.
Expand Down
4 changes: 2 additions & 2 deletions ring-core/src/ring/middleware/params.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{:form-params {}, :params {}})))

(defn params-request
"Adds parameters from the query string and the request body to the request
"Adds parameters from the request body and the query string to the request
map. See: wrap-params."
{:arglists '([request] [request options])
:added "1.2"}
Expand All @@ -51,7 +51,7 @@

:query-params - a map of parameters from the query string
:form-params - a map of parameters from the body
:params - a merged map of all types of parameter
:params - a merged map of all types of parameter, query-params last

Accepts the following options:

Expand Down