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(weak: false)

def etag(weak: false)
	if weak
		"W/\"#{digest.hexdigest}\""
	else
		"\"#{digest.hexdigest}\""
	end
end

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

@parameter callback [Block] The callback is invoked when the digest is complete.
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