Sha256: 917bb99602f2bed7f1b3f34d9fc231842f2cb1cd2c6576b74b9c9df45295d402

Contents?: true

Size: 1.19 KB

Versions: 17

Compression:

Stored size: 1.19 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'
          else
            'application/cbor'
          end

        headers = context.http_request.headers
        headers['Content-Type'] ||= content_type if content_type
        headers['Accept'] ||= 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

17 entries across 17 versions & 1 rubygems

Version Path
aws-sdk-core-3.220.2 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.220.1 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.220.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.219.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.218.1 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.218.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.217.1 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.217.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.216.1 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.216.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.215.1 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.215.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.214.1 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.214.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.213.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.212.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb
aws-sdk-core-3.211.0 lib/aws-sdk-core/rpc_v2/content_type_handler.rb