Protocol::HTTP1SourceProtocolHTTP1BodyFixed

class Fixed

Definitions

def read

Implementation

def read
	if @remaining > 0
		if @connection
			# `readpartial` will raise `EOFError` if the connection is finished, or `IOError` if the connection is closed.
			chunk = @connection.readpartial(@remaining)
			
			@remaining -= chunk.bytesize
			
			if @remaining == 0
				@connection.receive_end_stream!
				@connection = nil
			end
			
			return chunk
		end
		
		# If the connection has been closed before we have read the expected length, raise an error:
		raise EOFError, "connection closed before expected length was read!"
	end
end