 
 (defn- assoc-form-params
   "Parse and assoc parameters from the request body with the request."
-  [request]
+  [request encoding]
   (if-let [body (and (urlencoded-form? request) (:body request))]
-    (let [params (parse-params (slurp* body))]
+    (let [params (parse-params (slurp* body) encoding)]
       (merge-with merge request {:form-params params, :params params}))
     request))
 

  (:use clojure.contrib.str-utils)
  (:import java.net.URLDecoder))

(defvar *encoding* "UTF-8"
  "The encoding to use to decode urlencoded parameters. Defaults to
  UTF-8.")

(defn- urldecode
  "Decode a urlencoded string using the *encoding* var."
  [s]
  (URLDecoder/decode s *encoding*))

(defn- assoc-vec
  "Associate a key with a value. If the key already exists in the map,

  the request map:
    :query-params - a map of parameters from the query string
    :form-params  - a map of parameters from the body
    :params       - a merged map of both query and form parameters
  Takes an optional argument to specify the encoding of the parameters.
  Defaults to UTF-8."
  ([handler]
    (wrap-params handler "UTF-8"))
  ([handler encoding]
    (fn [request]
      (-> request
        (assoc-form-params encoding)
        (assoc-query-params encoding)
        handler))))
