ring-clojure / ring

Clojure HTTP server abstraction
MIT License
3.75k stars 519 forks source link

How to limit max upload size? #297

Open ertugrulcetin opened 7 years ago

ertugrulcetin commented 7 years ago

Is there any way to limit max upload size? If so could you provide an example please?

weavejester commented 7 years ago

You mean with the multipart middleware?

ertugrulcetin commented 7 years ago

On jetty side, I have an endpoint which accepts octet-stream I want it to fail if it exceeds the limit.

ertugrulcetin commented 7 years ago

Also yes, multipart middleware

ertugrulcetin commented 7 years ago

@weavejester any suggestions?

weavejester commented 7 years ago

You can create a custom multipart store that limits the files to a certain size. Take a look at ring.middleware.multipart-params.temp-file and ring.middleware.multipart-params.byte-array. You can adapt or wrap these multipart stores to limit the size of the items.

I don't currently have time to come up with an example for you, however.

ertugrulcetin commented 7 years ago

@weavejester thank you so much I think I figured it out! Are you gonna add this functionality to ring any time soon? That would be useful though

weavejester commented 7 years ago

When I get time, or someone sends me a PR, it would be useful functionality to have.