diff --git a/lib/rackup/stream.rb b/lib/rackup/stream.rb index 137f8ca..22b0a99 100644 --- a/lib/rackup/stream.rb +++ b/lib/rackup/stream.rb @@ -6,15 +6,16 @@ module Rackup # The input stream is an IO-like object which contains the raw HTTP POST data. When applicable, its external encoding must be “ASCII-8BIT” and it must be opened in binary mode, for Ruby 1.9 compatibility. The input stream must respond to gets, each, read and rewind. class Stream - def initialize(input = nil, output = Buffered.new) + def initialize(input = nil, output = nil) @input = input @output = output - raise ArgumentError, "Non-writable output!" unless output.respond_to?(:write) + raise ArgumentError, "Non-writable output!" if output && !output.respond_to?(:write) # Will hold remaining data in `#read`. @buffer = nil @closed = false + @closed_read = false end attr :input @@ -152,6 +153,7 @@ def flush end def close_read + @closed_read = true @input&.close @input = nil end @@ -182,7 +184,7 @@ def closed? # Whether there are any output chunks remaining? def empty? - @output.empty? + @output ? @output.empty? : true end private @@ -190,8 +192,7 @@ def empty? def read_next if @input return @input.read - else - @input = nil + elsif @closed_read raise IOError, "Stream is not readable, input has been closed!" end end