diff options
Diffstat (limited to 'lib/yahns/http_context.rb')
-rw-r--r-- | lib/yahns/http_context.rb | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/yahns/http_context.rb b/lib/yahns/http_context.rb index 97a0f82..547d41f 100644 --- a/lib/yahns/http_context.rb +++ b/lib/yahns/http_context.rb @@ -24,7 +24,7 @@ module Yahns::HttpContext # :nodoc: @check_client_connection = false @client_body_buffer_size = 112 * 1024 @client_header_buffer_size = 4000 - @client_max_body_size = 1024 * 1024 + @client_max_body_size = 1024 * 1024 # nil => infinity @input_buffering = true @output_buffering = true @persistent_connections = true @@ -34,7 +34,19 @@ module Yahns::HttpContext # :nodoc: # call this after forking def after_fork_init - @app = @yahns_rack.app_after_fork + @app = __wrap_app(@yahns_rack.app_after_fork) + end + + def __wrap_app(app) + # input_buffering == false is handled in http_client + return app if @client_max_body_size == nil + + require 'yahns/cap_input' + return app if @input_buffering == true + + # @input_buffering == false/:lazy + require 'yahns/max_body' + Yahns::MaxBody.new(app, @client_max_body_size) end # call this immediately after successful accept()/accept4() @@ -59,7 +71,11 @@ module Yahns::HttpContext # :nodoc: end def tmpio_for(len) - len && len <= @client_body_buffer_size ? - StringIO.new("") : Yahns::TmpIO.new + if len # Content-Length given + len <= @client_body_buffer_size ? StringIO.new("") : Yahns::TmpIO.new + else # chunked, unknown length + mbs = @client_max_body_size + mbs ? Yahns::CapInput.new(mbs) : Yahns::TmpIO.new + end end end |