Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/rackup/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -152,6 +153,7 @@ def flush
end

def close_read
@closed_read = true
@input&.close
@input = nil
end
Expand Down Expand Up @@ -182,16 +184,15 @@ def closed?

# Whether there are any output chunks remaining?
def empty?
@output.empty?
@output ? @output.empty? : true
end

private

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
Expand Down