Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to enforce a max upload size in Plack::Middleware without reading the entire body of the request?

I've just converted a PageKit (mod_perl) application to Plack. This means that I now need some way to enforce the POST_MAX/MAX_BODY that Apache2::Request would have previously handled. The easiest way to do this would probably be just to put nginx in front of the app, but the app is already sitting behind HAProxy and I don't see how to do this with HAProxy.

So, my question is how I might go about enforcing a maximum body size in Plack::Middleware without reading the entire body of the request first?

Specifically I'm concerned with file uploads. Checking size via Plack::Request::Upload is too late, since the entire body would have been read at this point. The app will be deployed via Starman, so psgix.streaming should be true.

like image 610
oalders Avatar asked Dec 17 '14 15:12

oalders


1 Answers

I got a response from Tatsuhiko Miyagawa via Twitter. He says, "if you deploy with Starman it's too late even with the middleware because the buffering is on. I'd do it with nginx".

This answers my particular question as I'm dealing with a Starman deployment.

He also noted that "rejecting a bigger upload before reading it on the backend could cause issues in general"

like image 172
oalders Avatar answered Nov 16 '22 12:11

oalders