class Aws::Plugins::HttpChecksum::Handler

@api private

Constants

CHUNK_SIZE

Public Instance Methods

call(context) click to toggle source
# File lib/aws-sdk-core/plugins/http_checksum.rb, line 13
def call(context)
  if checksum_required?(context) &&
     !context[:checksum_algorithms] # skip in favor of flexible checksum
    body = context.http_request.body
    context.http_request.headers['Content-Md5'] ||= md5(body)
  end
  @handler.call(context)
end

Private Instance Methods

checksum_required?(context) click to toggle source
# File lib/aws-sdk-core/plugins/http_checksum.rb, line 24
def checksum_required?(context)
  context.operation.http_checksum_required ||
    (context.operation.http_checksum &&
      context.operation.http_checksum['requestChecksumRequired'])
end
md5(value) click to toggle source

@param [File, Tempfile, IO#read, String] value @return [String<MD5>]

# File lib/aws-sdk-core/plugins/http_checksum.rb, line 32
def md5(value)
  if (value.is_a?(File) || value.is_a?(Tempfile)) &&
     !value.path.nil? && File.exist?(value.path)
    OpenSSL::Digest::MD5.file(value).base64digest
  elsif value.respond_to?(:read)
    md5 = OpenSSL::Digest::MD5.new
    update_in_chunks(md5, value)
    md5.base64digest
  else
    OpenSSL::Digest::MD5.digest(value).base64digest
  end
end
update_in_chunks(digest, io) click to toggle source
# File lib/aws-sdk-core/plugins/http_checksum.rb, line 45
def update_in_chunks(digest, io)
  loop do
    chunk = io.read(CHUNK_SIZE)
    break unless chunk
    digest.update(chunk)
  end
  io.rewind
end