Protocol::HTTP SourceProtocolHTTPBodyReadable

class Readable

def finish -> buffer the stream and close it.
def close(error = nil) -> close the stream immediately.

end

Definitions

def close(error = nil)

The consumer can call stop to signal that the stream output has terminated.

Implementation

def close(error = nil)
end

def empty?

Optimistically determine whether read (may) return any data. If this returns true, then calling read will definitely return nil. If this returns false, then calling read may return nil.

Implementation

def empty?
	false
end

def ready?

Whether calling read will return a chunk of data without blocking. We prefer pessimistic implementation, and thus default to false.

Implementation

def ready?
	false
end

def read

Read the next available chunk.

Implementation

def read
	nil
end

def stream?

Should the internal mechanism prefer to use Protocol::HTTP::Body::Readable#call?

Signature

returns Boolean

Implementation

def stream?
	false
end

def call(stream)

Write the body to the given stream.

Implementation

def call(stream)
	while chunk = self.read
		stream.write(chunk)
	end
ensure
	stream.close
end

def finish

Read all remaining chunks into a buffered body and close the underlying input.

Implementation

def finish
	# Internally, this invokes `self.each` which then invokes `self.close`.
	Buffered.for(self)
end

def each

Enumerate all chunks until finished, then invoke #close.

Implementation

def each
	return to_enum(:each) unless block_given?
	
	begin
		while chunk = self.read
			yield chunk
		end
	ensure
		self.close($!)
	end
end

def join

Read all remaining chunks into a single binary string using #each.

Implementation

def join
	buffer = String.new.force_encoding(Encoding::BINARY)
	
	self.each do |chunk|
		buffer << chunk
	end
	
	if buffer.empty?
		return nil
	else
		return buffer
	end
end