Add :max-file-size option to wrap-multipart-params#189
Closed
ryfow wants to merge 1 commit intoring-clojure:masterfrom
Closed
Add :max-file-size option to wrap-multipart-params#189ryfow wants to merge 1 commit intoring-clojure:masterfrom
ryfow wants to merge 1 commit intoring-clojure:masterfrom
Conversation
Member
|
Please see PR #98. |
Contributor
Author
|
Thanks. Sorry for not looking that up. After reading that thread I decided what I really want is a limit on the request size. This is what I ended up with. If you think this would be generally useful, I'll submit another PR. (defn- limited-stream [is max-size]
(proxy [LimitedInputStream]
[is max-size]
(raiseError [max count]
(throw (ex-info "Request too large."
{:max max
:count count
:type :request-too-large})))))
(defn wrap-request-size-limit [h max-size request-too-large-fn]
(fn [r]
(let [content-length (Long/valueOf (get-in r [:headers "content-length"] "0"))
body (:body r)]
(cond (< max-size content-length)
(request-too-large-fn r max-size content-length)
(instance? java.io.InputStream body)
(try
(h (assoc r :body (limited-stream body max-size)))
(catch Exception e
(let [d (ex-data e)]
(if (= (:type d) :request-too-large)
(request-too-large-fn r (:max d) (:count d))
(throw e)))))
:default
(h r))))) |
Member
|
I'm currently considering merging #98 into Ring 1.4, because the rewrite of the multipart namespace keeps getting delayed. In general, new middleware like |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'd like to be able to limit the size of the files read/created by wrap-multipart params. This change accomplishes that by setting
FileUpload.setFileSizeMaxbut I need some guidance on:Error handling. Right now it just propagates the commons-fileupload exception.
Testing. I don't see an example of testing the actual MIME parsing. I'm wondering what you'd like to see.
Thanks!
Ryan