about summary refs log tree commit homepage
path: root/lib/unicorn/http_request.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/unicorn/http_request.rb')
-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