about summary refs log tree commit homepage
path: root/lib/unicorn
diff options
context:
space:
mode:
Diffstat (limited to 'lib/unicorn')
-rw-r--r--lib/unicorn/http_request.rb3
-rw-r--r--lib/unicorn/tee_input.rb24
2 files changed, 6 insertions, 21 deletions
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb
index d9cb8b2..e25517b 100644
--- a/lib/unicorn/http_request.rb
+++ b/lib/unicorn/http_request.rb
@@ -27,7 +27,6 @@ module Unicorn
     }
 
     NULL_IO = StringIO.new(Z)
-    TEE = TeeInput.new
     DECHUNKER = ChunkedReader.new
     LOCALHOST = '127.0.0.1'.freeze
 
@@ -104,7 +103,7 @@ module Unicorn
           end
         end
 
-        inp = TEE.reopen(socket, length, body)
+        inp = TeeInput.new(socket, length, body)
         DEFAULTS[Const::STREAM_INPUT] ? inp : inp.consume
       else
         NULL_IO.closed? ? NULL_IO.reopen(Z) : NULL_IO
diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb
index 9e66837..ac9638d 100644
--- a/lib/unicorn/tee_input.rb
+++ b/lib/unicorn/tee_input.rb
@@ -15,30 +15,16 @@ require 'tempfile'
 module Unicorn
   class TeeInput
 
-    def initialize
-      @rd = @wr = @size = @input = nil
-      setup
-    end
-
-    def setup
-      @tmp = tmp = Tempfile.new(nil)
-      @rd.close if @rd
-      @rd = File.open(tmp.path, 'wb+')
-      @wr.close if @wr
-      @wr = File.open(tmp.path, 'wb')
+    def initialize(input, size = nil, buffer = nil)
+      @wr = Tempfile.new(nil)
+      @wr.binmode
+      @rd = File.open(@wr.path, 'rb')
+      @wr.unlink
       @rd.sync = @wr.sync = true
 
-      tmp.close!
-    end
-
-    def reopen(input, size = nil, buffer = nil)
-      @rd.seek(0)
-      @wr.seek(0)
-      @rd.truncate(0) # truncate read to flush luserspace read buffers
       @wr.write(buffer) if buffer
       @input = input
       @size = size # nil if chunked
-      self
     end
 
     def consume