class Protocol::HTTP1::Body::Remainder

Represents the remainder of the body, which reads all the data from the connection until it is finished.

def as_json(...)

@returns [Hash] JSON representation for tracing and debugging.
def as_json(...)
	super.merge(
		block_size: @block_size,
		state: @connection ? "open" : "closed"
	)
end

def close(error = nil)

@parameter error [Exception | Nil] the error that caused the connection to be closed, if any.

Close the connection.
def close(error = nil)
	self.discard
	
	super
end

def discard

Discard the body, which will close the connection and prevent further reads.
def discard
	if connection = @connection
		@connection = nil
		
		# Ensure no further requests can be read from the connection, as we are discarding the body which may not be fully read:
		connection.close_read
	end
end

def empty?

@returns [Boolean] true if the body is empty.
def empty?
	@connection.nil?
end

def initialize(connection, block_size: BLOCK_SIZE)

@parameter connection [Protocol::HTTP1::Connection] the connection to read the body from.

Initialize the body with the given connection.
def initialize(connection, block_size: BLOCK_SIZE)
	@connection = connection
	@block_size = block_size
end

def inspect

@returns [String] a human-readable representation of the body.
def inspect
	"#<#{self.class} #{@block_size} byte blocks, #{empty? ? 'finished' : 'reading'}>"
end

def read

@returns [String | Nil] the next chunk of data.

Read a chunk of data.
def read
	@connection&.readpartial(@block_size)
rescue EOFError
	if connection = @connection
		@connection = nil
		connection.receive_end_stream!
	end
	
	return nil
end