about summary refs log tree commit homepage
path: root/lib/rainbows/ev_core.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-01 21:29:34 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-01 21:30:24 -0800
commit945b5760d86b9dd00e65bd0625b98cf75f6a8257 (patch)
tree1261030d392993521ec9b3a608160c5d4f84bf5c /lib/rainbows/ev_core.rb
parent90789761f0cc78d3726f3a2eda1c5fe95c015ac2 (diff)
downloadrainbows-945b5760d86b9dd00e65bd0625b98cf75f6a8257.tar.gz
We may have other uses for this in the future...
Diffstat (limited to 'lib/rainbows/ev_core.rb')
-rw-r--r--lib/rainbows/ev_core.rb27
1 files changed, 15 insertions, 12 deletions
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?