From 9f1131f5972ba90c1c54c76cc97633447142b307 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 3 May 2010 15:19:53 -0700 Subject: add client_max_body_size config directive Since Rainbows! is supported when exposed directly to the Internet, administrators may want to limit the amount of data a user may upload in a single request body to prevent a denial-of-service via disk space exhaustion. This amount may be specified in bytes, the default limit being 1024*1024 bytes (1 megabyte). To override this default, a user may specify `client_max_body_size' in the Rainbows! block of their server config file: Rainbows! do client_max_body_size 10 * 1024 * 1024 end Clients that exceed the limit will get a "413 Request Entity Too Large" response if the request body is too large and the connection will close. For chunked requests, we have no choice but to interrupt during the client upload since we have no prior knowledge of the request body size. --- lib/rainbows/http_server.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/rainbows/http_server.rb') diff --git a/lib/rainbows/http_server.rb b/lib/rainbows/http_server.rb index ea2e23f..50231ff 100644 --- a/lib/rainbows/http_server.rb +++ b/lib/rainbows/http_server.rb @@ -85,6 +85,18 @@ module Rainbows raise ArgumentError, "keepalive must be a non-negative Integer" G.kato = nr end + + def client_max_body_size(nr) + err = "client_max_body_size must be nil or a non-negative Integer" + case nr + when nil + when Integer + nr >= 0 or raise ArgumentError, err + else + raise ArgumentError, err + end + Rainbows.max_bytes = nr + end end end -- cgit v1.2.3-24-ge0c7