Protocol::HTTPSourceProtocolHTTPBodyStream

class Stream

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.

Nested

Definitions

def write(buffer)

Write data to the underlying stream.

Signature

parameter buffer String

The data to write.

raises IOError

If the stream is not writable.

returns Integer

The number of bytes written.

Implementation

def write(buffer)
	if @output
		@output.write(buffer)
		return buffer.bytesize
	else
		raise IOError, "Stream is not writable, output has been closed!"
	end
end

def write_nonblock(buffer, exception: nil)

Write data to the stream using Protocol::HTTP::Body::Stream#write.

Provided for compatibility with IO-like objects.

Signature

parameter buffer String

The data to write.

parameter exception Boolean

Whether to raise an exception if the write would block, currently ignored.

returns Integer

The number of bytes written.

Implementation

def write_nonblock(buffer, exception: nil)
	write(buffer)
end

def <<(buffer)

Write data to the stream using Protocol::HTTP::Body::Stream#write.

Implementation

def <<(buffer)
	write(buffer)
end

def puts(*arguments, separator: NEWLINE)

Write lines to the stream.

The current implementation buffers the lines and writes them in a single operation.

Signature

parameter arguments Array(String)

The lines to write.

parameter separator String

The line separator, defaults to \n.

Implementation

def puts(*arguments, separator: NEWLINE)
	buffer = ::String.new
	
	arguments.each do |argument|
		buffer << argument << separator
	end
	
	write(buffer)
end

def flush

Flush the output stream.

This is currently a no-op.

Implementation

def flush
end

def close_read(error = nil)

Close the input body.

Implementation

def close_read(error = nil)
	if input = @input
		@input = nil
		@closed_read = true
		@buffer = nil
		
		input.close(error)
	end
end

def close_write(error = nil)

Close the output body.

Implementation

def close_write(error = nil)
	if output = @output
		@output = nil
		
		output.close_write(error)
	end
end

def close(error = nil)

Close the input and output bodies.

Implementation

def close(error = nil)
	self.close_read(error)
	self.close_write(error)
	
	return nil
ensure
	@closed = true
end

def closed?

Whether the stream has been closed.

Implementation

def closed?
	@closed
end

def empty?

Whether there are any output chunks remaining?

Implementation

def empty?
	@output.empty?
end