Sha256: 3439410c614e65da55b5bf55170dbdb9f5f190a8d7bc492364d07da999fa8472

Contents?: true

Size: 1.39 KB

Versions: 909

Compression:

Stored size: 1.39 KB

Contents

require 'openssl'
require 'base64'

module Aws
  module Plugins

    # @seahorse.client.option [Boolean] :compute_checksums (true)
    #   When `true` a MD5 checksum will be computed for every request that
    #   sends a body.  When `false`, MD5 checksums will only be computed
    #   for operations that require them.  Checksum errors returned by Amazon
    #   S3 are automatically retried up to `:retry_limit` times.
    class S3Md5s < Seahorse::Client::Plugin

      # Amazon S3 requires these operations to have an MD5 checksum
      REQUIRED_OPERATIONS = [
        :delete_objects,
        :put_bucket_cors,
        :put_bucket_lifecycle,
        :put_bucket_policy,
        :put_bucket_tagging,
      ]

      # @api private
      class Handler < Seahorse::Client::Handler

        def call(context)
          body = context.http_request.body
          if body.size > 0
            context.http_request.headers['Content-Md5'] ||= Checksums.md5(body)
          end
          @handler.call(context)
        end

      end

      option(:compute_checksums, true)

      def add_handlers(handlers, config)
        # priority set low to ensure md5 is computed AFTER the request is
        # built but before it is signed
        handlers.add(Handler, {
          priority: 10,
          step: :build,
          operations: config.compute_checksums ? nil : REQUIRED_OPERATIONS,
        })
      end

    end
  end
end

Version data entries

909 entries across 909 versions & 2 rubygems

Version Path
aws-sdk-core-2.11.632 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.631 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.630 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.629 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.628 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.627 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.626 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.625 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.624 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.623 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.622 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.621 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.620 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.619 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.618 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.617 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.616 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.615 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.614 lib/aws-sdk-core/plugins/s3_md5s.rb
aws-sdk-core-2.11.613 lib/aws-sdk-core/plugins/s3_md5s.rb