about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-06-10 16:00:08 -0700
committerEric Wong <normalperson@yhbt.net>2009-06-10 16:00:08 -0700
commit4651cd8b7c10d18bc745b84ebc7a55aad07d6077 (patch)
tree01ae0123891d16aa51ab18ff7c65d2dd1f3e733f /lib
parentb0013b043a15d77d810d5965157766c1af364db2 (diff)
downloadunicorn-4651cd8b7c10d18bc745b84ebc7a55aad07d6077.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/unicorn/http_request.rb23
1 files changed, 13 insertions, 10 deletions
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