Sha256: fcaaf7b3e8cecddcdc4d6952d13b5d89c2b081a149bb1fd9c52e2a48d0a36fa9

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

module Aws
  module Plugins

    # @seahorse.client.option [Boolean] :follow_redirects (true)
    #   When `true`, this client will follow 307 redirects returned
    #   by Amazon S3.
    class S3Redirects < Seahorse::Client::Plugin

      option(:follow_redirects, true)

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

        def call(context)
          response = @handler.call(context)
          if response.http_response.status_code == 307
            endpoint = response.http_response.headers['location']
            endpoint = Seahorse::Client::Http::Endpoint.new(endpoint)
            context.http_request.endpoint = endpoint
            context.http_response.body.truncate(0)
            @handler.call(context)
          else
            response
          end
        end

      end

      def add_handlers(handlers, config)
        if config.follow_redirects
          # we want to re-trigger request signing
          handlers.add(Handler, step: :sign, priority: 90)
        end
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aws-sdk-core-2.0.0.rc5 lib/aws/plugins/s3_redirects.rb
aws-sdk-core-2.0.0.rc4 lib/aws/plugins/s3_redirects.rb
aws-sdk-core-2.0.0.rc3 lib/aws/plugins/s3_redirects.rb
aws-sdk-core-2.0.0.rc2 lib/aws/plugins/s3_redirects.rb
aws-sdk-core-2.0.0.rc1 lib/aws/plugins/s3_redirects.rb