class Protocol::HTTP::Body::Digestable

Invokes a callback once the body has finished reading.

def self.wrap(message, digest = Digest::SHA256.new, &block)

def self.wrap(message, digest = Digest::SHA256.new, &block)
	if body = message&.body and !body.empty?
		message.body = self.new(message.body, digest, block)
	end
end

def digest

def digest
	@digest
end

def etag

def etag
	@digest.hexdigest.dump
end

def initialize(body, digest = Digest::SHA256.new, callback = nil)

def initialize(body, digest = Digest::SHA256.new, callback = nil)
	super(body)
	
	@digest = digest
	@callback = callback
end

def read

def read
	if chunk = super
		@digest.update(chunk)
		
		return chunk
	else
		@callback&.call(self)
		
		return nil
	end
end