class Remainder
Represents the remainder of the body, which reads all the data from the connection until it is finished.
Definitions
def initialize(connection, block_size: BLOCK_SIZE)
Initialize the body with the given connection.
Signature
-
parameter
connection
Protocol::HTTP1::Connection
the connection to read the body from.
Implementation
def initialize(connection, block_size: BLOCK_SIZE)
@connection = connection
@block_size = block_size
end
def empty?
Signature
-
returns
Boolean
true if the body is empty.
Implementation
def empty?
@connection.nil?
end
def discard
Discard the body, which will close the connection and prevent further reads.
Implementation
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 close(error = nil)
Close the connection.
Signature
-
parameter
error
Exception | Nil
the error that caused the connection to be closed, if any.
Implementation
def close(error = nil)
self.discard
super
end
def read
Read a chunk of data.
Signature
-
returns
String | Nil
the next chunk of data.
Implementation
def read
@connection&.readpartial(@block_size)
rescue EOFError
if connection = @connection
@connection = nil
connection.receive_end_stream!
end
return nil
end
def inspect
Signature
-
returns
String
a human-readable representation of the body.
Implementation
def inspect
"\#<#{self.class} state=#{@connection ? 'open' : 'closed'}>"
end