I think I want to limit the maximum file size and form payload that can reach a Rails 4 application, hosted on Heroku with the puma app server. I'd also like to kill these requests before they complete to free up server resources.
I'm assuming this can't be done in Rack, because it executes after the request has completed uploading?
With that in mind, it seems like the job of the web server, but I couldn't find mention of this in Puma. Does it have a mechanism I've missed for handling this kind of thing?
Alternatively would phusion passenger with nginx or apache handle this better?
http://httpd.apache.org/docs/1.3/mod/core.html#limitrequestbody http://www.cyberciti.biz/faq/apache-limiting-upload-size/
Why care:
- memory exhausted by large texts being turned into large ruby strings
- cpu wasted scanning very large strings doing sql escaping or html escaping or application validations
- server unable to accept new connections due to large backlog of clients uploading huge files (or huge form data)
Bonus points: the next step seems to be temp-banning repeat offenders in a firewall so they can't hit the web server. What technologies are good for that on Heroku?
Edit: relevant other thread Protect yourself against Dos attacks