 
   The following options are accepted
 
-  :encoding - character encoding to use for multipart parsing. If not
-              specified, uses the request character encoding, or \"UTF-8\"
-              if no request character encoding is set.
+  :encoding    - character encoding to use for multipart parsing. If not
+                 specified, uses the request character encoding, or \"UTF-8\"
+                 if no request character encoding is set.
 
-  :store    - a function that stores a file upload. The function should
-              expect a map with :filename, content-type and :stream keys,
-              and its return value will be used as the value for the
-              parameter in the multipart parameter map. The default storage
-              function is the temp-file-store."
+  :store       - a function that stores a file upload. The function should
+                 expect a map with :filename, content-type and :stream keys,
+                 and its return value will be used as the value for the
+                 parameter in the multipart parameter map. The default storage
+                 function is the temp-file-store.
+
+  :progress-fn - a function that gets called during uploads. The function
+                 should expect four parameters: request, bytes-read,
+                 content-length, and item-count."
   {:arglists '([handler] [handler options])}
   [handler & [options]]
   (fn [request]

        encoding (or (:encoding options)
                     (req/character-encoding request)
                     "UTF-8")
        params   (if (multipart-form? request)
                   (parse-multipart-params request encoding store)
                   {})]
    (merge-with merge request
                {:multipart-params params}


(defn- parse-multipart-params
  "Parse a map of multipart parameters from the request."
  [request encoding store progress-fn]
  (->> (request-context request encoding)
       (file-item-seq request progress-fn)
       (map #(parse-file-item % store encoding))
       (reduce (fn [m [k v]] (assoc-conj m k v)) {})))

