                 character encoding is set."
   [handler & [opts]]
   (fn [request]
-    (let [encoding (or (:encoding opts)
-                       (:character-encoding request)
-                       "UTF-8")
-          request  (if (:form-params request)
-                     request
-                     (assoc-form-params request encoding))
-          request  (if (:query-params request)
-                     request
-                     (assoc-query-params request encoding))]
-      (handler request))))
+    (-> request
+        (params-request opts)
+        handler)))

  (if-let [^String type (:content-type request)]
    (.startsWith type "application/x-www-form-urlencoded")))

(defn- assoc-form-params
  "Parse and assoc parameters from the request body with the request."
  [request encoding]
  (merge-with merge request

      (let [params (parse-params (slurp body :encoding encoding) encoding)]
        {:form-params params, :params params})
      {:form-params {}, :params {}})))

(defn params-request [request & [opts]]
  (let [encoding (or (:encoding opts)
                     (:character-encoding request)
                     "UTF-8")
        request  (if (:form-params request)
                   request
                   (assoc-form-params request encoding))]
    (if (:query-params request)
      request
      (assoc-query-params request encoding))))

(defn wrap-params
  "Middleware to parse urlencoded parameters from the query string and form
