|
16 | 16 | [cmr.common.config :refer [defconfig]] |
17 | 17 | [cmr.common.mime-types :as mt] |
18 | 18 | [cmr.common.services.errors :as svc-errors] |
19 | | - [cmr.search.api.routes :as api-routes] |
| 19 | + [cmr.search.api.routes :as api-routes] |
20 | 20 | [cmr.search.data.granule-counts-cache :as granule-counts-cache] |
21 | 21 | [cmr.search.middleware.shapefile :as shapefile] |
22 | 22 | [cmr.search.middleware.shapefile-simplification :as shapefile-simplifier] |
23 | 23 | [cmr.search.services.messages.common-messages :as msg] |
24 | 24 | [cmr.search.site.routes :as site-routes] |
25 | 25 | [compojure.core :refer [GET POST context routes]] |
26 | 26 | [ring.middleware.keyword-params :as keyword-params] |
| 27 | + [ring.middleware.multipart-params :as multipart] |
27 | 28 | [ring.middleware.nested-params :as nested-params] |
28 | 29 | [ring.middleware.params :as params])) |
29 | 30 |
|
|
55 | 56 | [(msg/mixed-arity-parameter-msg mixed-param)])) |
56 | 57 | (handler request))) |
57 | 58 |
|
| 59 | +(defn parse-multipart-body [request] |
| 60 | + (let [parsed (multipart/multipart-params-request request)] |
| 61 | + (string/join "&" (for [[k v] (:multipart-params parsed)] |
| 62 | + (str (name k) "=" v))))) |
| 63 | + |
58 | 64 | (defn copy-of-body-handler |
59 | 65 | "Copies the body into a new attribute called :body-copy so that after a post |
60 | 66 | of form content type the original body can still be read. The default ring |
61 | 67 | params reads the body and parses it and we don't have access to it." |
62 | 68 | [handler] |
63 | 69 | (fn [request] |
64 | | - (let [^String body (slurp (:body request))] |
| 70 | + (let [content-type (get-in request [:headers "content-type"]) |
| 71 | + body (if (and content-type (string/starts-with? content-type "multipart/form-data")) |
| 72 | + (parse-multipart-body request) |
| 73 | + (slurp (:body request)))] |
65 | 74 | (handler (assoc |
66 | 75 | request |
67 | 76 | :body-copy body |
|
0 commit comments