Skip to content

Commit

Permalink
Remove contrib dependencies form r.m.multipart params.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcgrana committed Nov 1, 2010
1 parent 821c675 commit d778ce4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
11 changes: 6 additions & 5 deletions ring-core/src/ring/middleware/multipart_params.clj
@@ -1,7 +1,6 @@
(ns ring.middleware.multipart-params
"Parse multipart upload into params."
(:use [clojure.contrib.def :only (defvar-)]
[ring.middleware.params :only (assoc-param)])
(:use [ring.middleware.params :only (assoc-param)])
(:import (org.apache.commons.fileupload
FileUpload RequestContext)
(org.apache.commons.fileupload.disk
Expand All @@ -14,12 +13,14 @@
(if-let [^String content-type (:content-type request)]
(.startsWith content-type "multipart/form-data")))

(defvar- ^FileUpload file-upload
(def ^{:private true
:type FileUpload
:doc "Uploader class to save multipart form values to temporary files."}
file-upload
(FileUpload.
(doto (DiskFileItemFactory.)
(.setSizeThreshold -1)
(.setFileCleaningTracker nil)))
"Uploader class to save multipart form values to temporary files.")
(.setFileCleaningTracker nil))))

(defn- request-context
"Create a RequestContext object from a request map."
Expand Down
17 changes: 12 additions & 5 deletions ring-core/test/ring/middleware/multipart_params_test.clj
Expand Up @@ -6,15 +6,22 @@
[ring.util.test :as tu])
(:import java.io.File))

(defvar- upload-content-type
(def ^{:private true}
upload-content-type
"multipart/form-data; boundary=----WebKitFormBoundaryAyGUY6aMxOI6UF5s")

(defvar- upload-content-length 188)
(def ^{:private true}
upload-content-length
188)

(defvar- upload-body (tu/string-input-stream
"------WebKitFormBoundaryAyGUY6aMxOI6UF5s\r\nContent-Disposition: form-data; name=\"upload\"; filename=\"test.txt\"\r\nContent-Type: text/plain\r\n\r\nfoo\r\n\r\n------WebKitFormBoundaryAyGUY6aMxOI6UF5s--"))
(def ^{:private true}
upload-body
(tu/string-input-stream
"------WebKitFormBoundaryAyGUY6aMxOI6UF5s\r\nContent-Disposition: form-data; name=\"upload\"; filename=\"test.txt\"\r\nContent-Type: text/plain\r\n\r\nfoo\r\n\r\n------WebKitFormBoundaryAyGUY6aMxOI6UF5s--"))

(defvar- wrapped-echo (wrap-multipart-params identity))
(def ^{:private true}
wrapped-echo
(wrap-multipart-params identity))

(deftest test-wrap-multipart-params
(let [req {:content-type upload-content-type
Expand Down

0 comments on commit d778ce4

Please sign in to comment.