Sha256: 11ec7d9d1f9a0cc7509b4c958d6fa3b543e207a6fdc3e3e42bcfc8be9c008ce8

Contents?: true

Size: 1.05 KB

Versions: 115

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Aws
  module Plugins
    # @api private
    class RecursionDetection < Seahorse::Client::Plugin

      # @api private
      class Handler < Seahorse::Client::Handler
        def call(context)

          unless context.http_request.headers.key?('x-amzn-trace-id')
            if ENV['AWS_LAMBDA_FUNCTION_NAME'] &&
              (trace_id = validate_header(ENV['_X_AMZN_TRACE_ID']))
              context.http_request.headers['x-amzn-trace-id'] = trace_id
            end
          end
          @handler.call(context)
        end

        private
        def validate_header(header_value)
          return unless header_value

          if (header_value.chars & (0..31).map(&:chr)).any?
            raise ArgumentError, 'Invalid _X_AMZN_TRACE_ID value: '\
              'contains ASCII control characters'
          end
          header_value
        end
      end

      # should be at the end of build so that
      # modeled traits / service customizations apply first
      handler(Handler, step: :build, order: 99)
    end
  end
end

Version data entries

115 entries across 115 versions & 1 rubygems

Version Path
aws-sdk-core-3.214.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.213.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.212.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.211.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.210.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.209.1 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.209.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.208.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.207.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.206.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.205.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.204.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.203.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.202.2 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.202.1 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.202.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.201.5 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.201.4 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.201.3 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.201.2 lib/aws-sdk-core/plugins/recursion_detection.rb