Sha256: fb46c3001e4e1152a6b38b05c6877eddbb4892e6564beddc8f0d7ddc9b86a9c9

Contents?: true

Size: 1.16 KB

Versions: 20

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Aws
  module RpcV2
    class ContentTypeHandler < Seahorse::Client::Handler
      def call(context)
        content_type =
          if eventstream_input?(context)
            'application/vnd.amazon.eventstream'
          elsif !empty_input_structure?(context)
            'application/cbor'
          end
        accept =
          if eventstream_output?(context)
            'application/vnd.amazon.eventstream'
          end

        headers = context.http_request.headers
        headers['Content-Type'] ||= content_type if content_type
        headers['Accept'] ||= accept if accept
        @handler.call(context)
      end

      private

      def eventstream_input?(context)
        context.operation.input.shape.members.each do |_, ref|
          return true if ref.eventstream
        end
        false
      end

      def eventstream_output?(context)
        context.operation.output.shape.members.each do |_, ref|
          return true if ref.eventstream
        end
        false
      end

      def empty_input_structure?(context)
        context.operation.input.shape.struct_class == EmptyStructure
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
aws-sdk-core-3.210.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.209.1 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.209.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.208.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.207.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.206.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.205.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.204.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.203.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.202.2 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.202.1 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.202.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.201.5 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.201.4 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.201.3 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.201.2 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.201.1 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.201.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.200.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.199.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb