|
139 | 139 |
|
140 | 140 | (defn default-invalid-filename-handler
|
141 | 141 | ([request]
|
142 |
| - (-> request ::invalid-filename-exception .getMessage response/bad-request)) |
| 142 | + (-> request ::invalid-filename response/bad-request)) |
143 | 143 | ([request respond raise]
|
144 | 144 | (respond (default-invalid-filename-handler request))))
|
145 | 145 |
|
| 146 | +(defn- add-invalid-filename-to-req |
| 147 | + [request invalid-filename-exception] |
| 148 | + (assoc request ::invalid-filename (.getName invalid-filename-exception) )) |
| 149 | + |
146 | 150 | (defn wrap-multipart-params
|
147 | 151 | "Middleware to parse multipart parameters from a request. Adds the following
|
148 | 152 | keys to the request map:
|
|
177 | 181 | :invalid-filename-handler
|
178 | 182 | - A handler that gets called when the file being uploaded has an invalid name.
|
179 | 183 | When this handler receives the request it can expect one additional key,
|
180 |
| - ::invalid-filename-exception, which contains an InvalidFileNameException." |
| 184 | + ::invalid-filename, which contains the name of the invalid file." |
181 | 185 | ([handler]
|
182 | 186 | (wrap-multipart-params handler {}))
|
183 | 187 | ([handler options]
|
|
188 | 192 | (multipart-params-request request options)
|
189 | 193 | (catch InvalidFileNameException ex ex))]
|
190 | 194 | (if (instance? InvalidFileNameException req-or-ex)
|
191 |
| - (invalid-filename-handler |
192 |
| - (assoc request ::invalid-filename-exception req-or-ex)) |
| 195 | + (-> request |
| 196 | + (add-invalid-filename-to-req req-or-ex) |
| 197 | + invalid-filename-handler) |
193 | 198 | (handler req-or-ex))))
|
194 | 199 | ([request respond raise]
|
195 | 200 | (let [req-or-ex (try
|
196 | 201 | (multipart-params-request request options)
|
197 | 202 | (catch InvalidFileNameException ex ex))]
|
198 | 203 | (if (instance? InvalidFileNameException req-or-ex)
|
199 |
| - (invalid-filename-handler |
200 |
| - (assoc request ::invalid-filename-exception req-or-ex) respond raise) |
| 204 | + (-> request |
| 205 | + (add-invalid-filename-to-req req-or-ex) |
| 206 | + (invalid-filename-handler respond raise)) |
201 | 207 | (handler req-or-ex respond raise))))))))
|
0 commit comments