From f3b379f938719ed7cdfdf2eb92491db276e2da07 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 14 Aug 2009 21:03:39 -0700 Subject: http_request: reinstate empty StringIO optimization This makes a noticeable difference on light GET/HEAD requests. Heck, even the tests run a few seconds faster. --- lib/unicorn/http_request.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 26eff1f..a0d811c 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -1,4 +1,5 @@ # coding:binary +require 'stringio' require 'unicorn_http' module Unicorn @@ -17,6 +18,7 @@ module Unicorn "SERVER_SOFTWARE" => "Unicorn #{Const::UNICORN_VERSION}".freeze } + NULL_IO = StringIO.new(Z) LOCALHOST = '127.0.0.1'.freeze # Being explicitly single-threaded, we have certain advantages in @@ -71,7 +73,8 @@ module Unicorn # Handles dealing with the rest of the request # returns a # Rack environment if successful def handle_body(socket) - REQ[Const::RACK_INPUT] = Unicorn::TeeInput.new(socket) + REQ[Const::RACK_INPUT] = 0 == PARSER.content_length ? + NULL_IO : Unicorn::TeeInput.new(socket) REQ.update(DEFAULTS) end -- cgit v1.2.3-24-ge0c7