On Thu, Nov 18, 2010 at 8:47 PM, Mohit Anchlia <mohitanch...@gmail.com> wrote: > I have a requirement to look at content length and if it is greatar > than desired size then return error message. So psuedo code is like:
Easier solution: use LImitRequestBody, but have a perl handler that sets a custom response text for 413's as appropriate. something like: sub handler { my $r = shift; if ($r->uri =~ /abc/) { $r->custom_response What if the request has no Content-Length: header at all? Do you let it through then, no matter how big the body is? > if content_length > 32G > then > if url contains /abc/ > then > echo "0|abc|Bad length" # pipe delimited format that some > clients api support > else if url contains /def/ > echo "<xml><message>Bad request</message><xml>" # client supporting XML > fi > fi Yuck. I would move the logic into whatever handles the API calls rather than duplicating the mapping from URI's to code in two places. That's just asking for things to get out of synch. > I first thought of using LimitRequestBody but that didn't work for me. > So now I am thinking if using perl handlers. > > P.S. Note: Our requests are mod-jk requests. So if content length > check succeeds then hand over the request to mod jk workers wihch then > send it to jboss app server. > > I tried to write code but still unsure of few thing: > > 1. If I return HTTP_REQUEST_ENTITY_TOO_LARGE response then would it > still continue sending the request to mod_jk. Or would it be returned > back to the client? When does apache decide if request need to be > stopped and send back to the client. > 2. Does my code look ok and something that will work? Can someone > please suggest? > > > This is my sample code > > sub content_handler { > my $r = shift; > my $uri = $r->uri; > if ( $r->header_in("Content-length") lt 20000000) { > return Apache2::Const::OK; # Continue sending request to mod jk worker > } > $r->send_http_header; > if ($uri =~ /xml/){ > $r->content_type("text/xml"); > $r->print("File too large|Bye"); #Send pipe delimited back to the > client assuming it will not continue sending this request to mod_jk > worker > }else{ > $r->content_type("text/plain"); > $r->print ("<xml><Message>Too Large, Bye!!</Message></xml>"); > #Send xml delimited back to the client assuming it will not continue > sending this request to mod_jk worker > } > > return Apache2::Const::HTTP_REQUEST_ENTITY_TOO_LARGE; # Return back to client > -- Mark J. Reed <markjr...@gmail.com>