From 8e1f0620e567cd676902e4ed34edb042f28ec3b0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 27 Sep 2009 17:26:59 -0700 Subject: http_request: simplify and remove handle_body method It is simpler and even slightly faster in micro benchmarks when inlined. --- lib/unicorn/http_request.rb | 25 ++++++++----------------- 1 file 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) -- cgit v1.2.3-24-ge0c7