From 4651cd8b7c10d18bc745b84ebc7a55aad07d6077 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 10 Jun 2009 16:00:08 -0700 Subject: Optimize body-less GET/HEAD requests (again) No point in making syscalls to deal with empty bodies. Reinstate usage of the NULL_IO object which allows us to avoid allocating new objects. --- lib/unicorn/http_request.rb | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 58a5554..d9cb8b2 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -94,19 +94,22 @@ module Unicorn # Handles dealing with the rest of the request # returns a Rack environment if successful def handle_body(socket) - http_body = PARAMS.delete(:http_body) - - length = PARAMS[Const::CONTENT_LENGTH].to_i - if te = PARAMS[Const::HTTP_TRANSFER_ENCODING] - if /chunked/i =~ te - socket = DECHUNKER.reopen(socket, http_body) - length = http_body = nil + PARAMS[Const::RACK_INPUT] = if (body = PARAMS.delete(:http_body)) + length = PARAMS[Const::CONTENT_LENGTH].to_i + + if te = PARAMS[Const::HTTP_TRANSFER_ENCODING] + if /chunked/i =~ te + socket = DECHUNKER.reopen(socket, body) + length = body = nil + end end + + inp = TEE.reopen(socket, length, body) + DEFAULTS[Const::STREAM_INPUT] ? inp : inp.consume + else + NULL_IO.closed? ? NULL_IO.reopen(Z) : NULL_IO end - inp = TEE.reopen(socket, length, http_body) - PARAMS[Const::RACK_INPUT] = - DEFAULTS[Const::STREAM_INPUT] ? inp : inp.consume PARAMS.update(DEFAULTS) end -- cgit v1.2.3-24-ge0c7