From 6b750f5f952963009a2e6e8702fc8f3d8adc94ea Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 8 Dec 2010 18:35:27 -0800 Subject: respect "rewindable_input false" in Unicorn config This was completely overlooked for the Rainbows 2.0.x releases. --- lib/rainbows/base.rb | 1 + lib/rainbows/process_client.rb | 9 +++------ lib/rainbows/rack_input.rb | 17 +++++++++++++++++ lib/rainbows/revactor.rb | 3 ++- t/t0113-rewindable-input-false.sh | 26 ++++++++++++++++++++++++++ t/t0113.ru | 12 ++++++++++++ t/t0114-rewindable-input-true.sh | 26 ++++++++++++++++++++++++++ t/t0114.ru | 12 ++++++++++++ 8 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 lib/rainbows/rack_input.rb create mode 100755 t/t0113-rewindable-input-false.sh create mode 100644 t/t0113.ru create mode 100755 t/t0114-rewindable-input-true.sh create mode 100644 t/t0114.ru diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb index 3027aba..bf9ef87 100644 --- a/lib/rainbows/base.rb +++ b/lib/rainbows/base.rb @@ -18,6 +18,7 @@ module Rainbows::Base super(worker) Rainbows::Response.setup(self.class) Rainbows::MaxBody.setup + Rainbows::RackInput.setup G.tmp = worker.tmp listeners = Rainbows::HttpServer::LISTENERS diff --git a/lib/rainbows/process_client.rb b/lib/rainbows/process_client.rb index 3055b9d..271185d 100644 --- a/lib/rainbows/process_client.rb +++ b/lib/rainbows/process_client.rb @@ -1,12 +1,11 @@ # -*- encoding: binary -*- # :enddoc: +require 'rainbows/rack_input' module Rainbows::ProcessClient G = Rainbows::G include Rainbows::Response HttpParser = Unicorn::HttpParser - NULL_IO = Unicorn::HttpRequest::NULL_IO - RACK_INPUT = Unicorn::HttpRequest::RACK_INPUT - TeeInput = Unicorn::TeeInput + include Rainbows::RackInput include Rainbows::Const # once a client is accepted, it is processed in its entirety here @@ -25,9 +24,7 @@ module Rainbows::ProcessClient buf << buf2 end - env[CLIENT_IO] = client - env[RACK_INPUT] = 0 == hp.content_length ? - NULL_IO : TeeInput.new(client, hp) + set_input(env, hp, client) env[REMOTE_ADDR] = remote_addr status, headers, body = APP.call(env.update(RACK_DEFAULTS)) diff --git a/lib/rainbows/rack_input.rb b/lib/rainbows/rack_input.rb new file mode 100644 index 0000000..df51ac1 --- /dev/null +++ b/lib/rainbows/rack_input.rb @@ -0,0 +1,17 @@ +# -*- encoding: binary -*- +# :enddoc: +# only used by synchronous interfaces +module Rainbows::RackInput + NULL_IO = Unicorn::HttpRequest::NULL_IO + RACK_INPUT = Unicorn::HttpRequest::RACK_INPUT + CLIENT_IO = Rainbows::Const::CLIENT_IO + + def self.setup + const_set(:IC, Unicorn::HttpRequest.input_class) + end + + def set_input(env, hp, client) + env[RACK_INPUT] = 0 == hp.content_length ? NULL_IO : IC.new(client, hp) + env[CLIENT_IO] = client + end +end diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb index 51f6c1f..a181df1 100644 --- a/lib/rainbows/revactor.rb +++ b/lib/rainbows/revactor.rb @@ -53,7 +53,7 @@ module Rainbows::Revactor env[CLIENT_IO] = client env[RACK_INPUT] = 0 == hp.content_length ? - NULL_IO : Unicorn::TeeInput.new(ts = TeeSocket.new(client), hp) + NULL_IO : IC.new(ts = TeeSocket.new(client), hp) env[REMOTE_ADDR] = remote_addr status, headers, body = app.call(env.update(RACK_DEFAULTS)) @@ -87,6 +87,7 @@ module Rainbows::Revactor init_worker_process(worker) require 'rainbows/revactor/body' self.class.__send__(:include, Rainbows::Revactor::Body) + self.class.const_set(:IC, Unicorn::HttpRequest.input_class) RD_ARGS[:timeout] = G.kato if G.kato > 0 nr = 0 limit = worker_connections diff --git a/t/t0113-rewindable-input-false.sh b/t/t0113-rewindable-input-false.sh new file mode 100755 index 0000000..c906106 --- /dev/null +++ b/t/t0113-rewindable-input-false.sh @@ -0,0 +1,26 @@ +#!/bin/sh +. ./test-lib.sh +skip_models EventMachine NeverBlock Rev RevThreadSpawn RevThreadPool + +t_plan 4 "rewindable_input toggled to false" + +t_begin "setup and start" && { + rainbows_setup + echo rewindable_input false >> $unicorn_config + rainbows -D -c $unicorn_config t0113.ru + rainbows_wait_start +} + +t_begin "ensure worker is started" && { + test xOK = x$(curl -T t0113.ru -H Expect: -vsSf http://$listen/) +} + +t_begin "killing succeeds" && { + kill $rainbows_pid +} + +t_begin "check stderr" && { + check_stderr +} + +t_done diff --git a/t/t0113.ru b/t/t0113.ru new file mode 100644 index 0000000..48a3a34 --- /dev/null +++ b/t/t0113.ru @@ -0,0 +1,12 @@ +#\ -E none +use Rack::ContentLength +use Rack::ContentType, 'text/plain' +app = lambda do |env| + case env['rack.input'] + when Unicorn::StreamInput + [ 200, {}, %w(OK) ] + else + [ 500, {}, %w(NO) ] + end +end +run app diff --git a/t/t0114-rewindable-input-true.sh b/t/t0114-rewindable-input-true.sh new file mode 100755 index 0000000..349449c --- /dev/null +++ b/t/t0114-rewindable-input-true.sh @@ -0,0 +1,26 @@ +#!/bin/sh +. ./test-lib.sh +skip_models EventMachine NeverBlock Rev RevThreadSpawn RevThreadPool + +t_plan 4 "rewindable_input toggled to true" + +t_begin "setup and start" && { + rainbows_setup + echo rewindable_input true >> $unicorn_config + rainbows -D -c $unicorn_config t0114.ru + rainbows_wait_start +} + +t_begin "ensure worker is started" && { + test xOK = x$(curl -T t0114.ru -sSf http://$listen/) +} + +t_begin "killing succeeds" && { + kill $rainbows_pid +} + +t_begin "check stderr" && { + check_stderr +} + +t_done diff --git a/t/t0114.ru b/t/t0114.ru new file mode 100644 index 0000000..b0bd2b7 --- /dev/null +++ b/t/t0114.ru @@ -0,0 +1,12 @@ +#\ -E none +use Rack::ContentLength +use Rack::ContentType, 'text/plain' +app = lambda do |env| + case env['rack.input'] + when Unicorn::TeeInput + [ 200, {}, %w(OK) ] + else + [ 500, {}, %w(NO) ] + end +end +run app -- cgit v1.2.3-24-ge0c7