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.151.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.150.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.149.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.148.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.147.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.146.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.145.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.144.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.143.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.142.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.141.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.140.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.139.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.138.0 lib/aws-sdk-core/plugins/recursion_detection.rb
aws-sdk-core-3.137.0 lib/aws-sdk-core/plugins/recursion_detection.rb