about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-09-27 17:26:59 -0700
committerEric Wong <normalperson@yhbt.net>2009-09-27 17:26:59 -0700
commit8e1f0620e567cd676902e4ed34edb042f28ec3b0 (patch)
treef8f5238077fcbe06541ba62d8c37d0308a48d20f
parent0d43e19396a325ac9fe8b6c0a6031c87c0202697 (diff)
downloadunicorn-8e1f0620e567cd676902e4ed34edb042f28ec3b0.tar.gz
It is simpler and even slightly faster in micro benchmarks
when inlined.
-rw-r--r--lib/unicorn/http_request.rb25
1 files changed, 8 insertions, 17 deletions
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb
index 2d191d7..4a78e73 100644
--- a/lib/unicorn/http_request.rb
+++ b/lib/unicorn/http_request.rb
@@ -56,24 +56,15 @@ module Unicorn
                     TCPSocket === socket ? socket.peeraddr.last : LOCALHOST
 
       # short circuit the common case with small GET requests first
-      PARSER.headers(REQ, socket.readpartial(Const::CHUNK_SIZE, BUF)) and
-          return handle_body(socket)
+      if PARSER.headers(REQ, socket.readpartial(Const::CHUNK_SIZE, BUF)).nil?
+        data = BUF.dup # socket.readpartial will clobber data
 
-      data = BUF.dup # socket.readpartial will clobber data
-
-      # Parser is not done, queue up more data to read and continue parsing
-      # an Exception thrown from the PARSER will throw us out of the loop
-      begin
-        BUF << socket.readpartial(Const::CHUNK_SIZE, data)
-        PARSER.headers(REQ, BUF) and return handle_body(socket)
-      end while true
-    end
-
-    private
-
-    # Handles dealing with the rest of the request
-    # returns a # Rack environment if successful
-    def handle_body(socket)
+        # Parser is not done, queue up more data to read and continue parsing
+        # an Exception thrown from the PARSER will throw us out of the loop
+        begin
+          BUF << socket.readpartial(Const::CHUNK_SIZE, data)
+        end while PARSER.headers(REQ, BUF).nil?
+      end
       REQ[Const::RACK_INPUT] = 0 == PARSER.content_length ?
                    NULL_IO : Unicorn::TeeInput.new(socket, REQ, PARSER, BUF)
       REQ.update(DEFAULTS)