Skip to content

Commit 622c245

Browse files
committed
Refactor multipart item seq into iterable
1 parent fdf9d04 commit 622c245

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

ring-core/src/ring/middleware/multipart_params.clj

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@
4444
(getCharacterEncoding [_] encoding)
4545
(getInputStream [_] (:body request))))
4646

47-
(defn- file-item-iterator-seq [^FileItemIterator it]
48-
(lazy-seq
49-
(when (.hasNext it)
50-
(cons (.next it) (file-item-iterator-seq it)))))
51-
52-
(defn- file-item-seq [^FileUpload upload context]
53-
(file-item-iterator-seq (.getItemIterator upload context)))
47+
(defn- file-item-iterable [^FileUpload upload context]
48+
(reify Iterable
49+
(iterator [_]
50+
(let [it (.getItemIterator upload context)]
51+
(reify java.util.Iterator
52+
(hasNext [_] (.hasNext it))
53+
(next [_] (.next it)))))))
5454

5555
(defn- parse-content-type-charset [^FileItemStream item]
5656
(some->> (.getContentType item) parsing/find-content-type-charset))
@@ -96,12 +96,13 @@
9696
(req/character-encoding request)
9797
"UTF-8")]
9898
(->> (request-context request fallback-encoding)
99-
(file-item-seq (file-upload request options))
100-
(map-indexed (fn [i item]
101-
(if (and max-file-count (>= i max-file-count))
102-
(throw (ex-info "Max file count exceeded"
103-
{:max-file-count max-file-count}))
104-
(parse-file-item item store))))
99+
(file-item-iterable (file-upload request options))
100+
(sequence
101+
(map-indexed (fn [i item]
102+
(if (and max-file-count (>= i max-file-count))
103+
(throw (ex-info "Max file count exceeded"
104+
{:max-file-count max-file-count}))
105+
(parse-file-item item store)))))
105106
(build-param-map encoding fallback-encoding))))
106107

107108
(defn multipart-params-request

0 commit comments

Comments
 (0)