From 945b5760d86b9dd00e65bd0625b98cf75f6a8257 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 1 Dec 2010 21:29:34 -0800 Subject: ev_core: split out prepare_request_body We may have other uses for this in the future... --- lib/rainbows/ev_core.rb | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'lib/rainbows/ev_core.rb') diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb index 3865d79..4dd884a 100644 --- a/lib/rainbows/ev_core.rb +++ b/lib/rainbows/ev_core.rb @@ -43,6 +43,19 @@ module Rainbows::EvCore rv end + def prepare_request_body + # since we don't do streaming input, we have no choice but + # to take over 100-continue handling from the Rack application + if @env[HTTP_EXPECT] =~ /\A100-continue\z/i + write(EXPECT_100_RESPONSE) + @env.delete(HTTP_EXPECT) + end + @input = CapInput.new(@hp.content_length, self) + @hp.filter_body(@buf2 = "", @buf) + @input << @buf2 + on_read("") + end + # TeeInput doesn't map too well to this right now... def on_read(data) case @state @@ -50,21 +63,11 @@ module Rainbows::EvCore @buf << data @hp.parse or return @state = :body - len = @hp.content_length - if len == 0 + if 0 == @hp.content_length @input = NULL_IO app_call # common case else # nil or len > 0 - # since we don't do streaming input, we have no choice but - # to take over 100-continue handling from the Rack application - if @env[HTTP_EXPECT] =~ /\A100-continue\z/i - write(EXPECT_100_RESPONSE) - @env.delete(HTTP_EXPECT) - end - @input = CapInput.new(len, self) - @hp.filter_body(@buf2 = "", @buf) - @input << @buf2 - on_read("") + prepare_request_body end when :body if @hp.body_eof? -- cgit v1.2.3-24-ge0c7