Sha256: df34a3bce6b70532089eb243302a45ee51b6bc89fb2c5e46edce6346d782c702

Contents?: true

Size: 1.8 KB

Versions: 109

Compression:

Stored size: 1.8 KB

Contents

require 'time'
require 'base64'

module Aws
  module Rest
    module Request
      class Headers

        include Seahorse::Model::Shapes

        # @param [Seahorse::Model::ShapeRef] rules
        def initialize(rules)
          @rules = rules
        end

        # @param [Seahorse::Client::Http::Request] http_req
        # @param [Hash] params
        def apply(http_req, params)
          @rules.shape.members.each do |name, ref|
            value = params[name]
            next if value.nil?
            case ref.location
            when 'header' then apply_header_value(http_req.headers, ref, value)
            when 'headers' then apply_header_map(http_req.headers, ref, value)
            end
          end
        end

        private

        def apply_header_value(headers, ref, value)
          value = apply_json_trait(value) if ref['jsonvalue']
          headers[ref.location_name] =
            case ref.shape
            when TimestampShape then timestamp(ref, value)
            else value.to_s
            end
        end

        def timestamp(ref, value)
          case ref['timestampFormat'] || ref.shape['timestampFormat']
          when 'unixTimestamp' then value.to_i
          when 'iso8601' then value.utc.iso8601
          else
            # header default to rfc822
            value.utc.httpdate
          end
        end

        def apply_header_map(headers, ref, values)
          prefix = ref.location_name || ''
          values.each_pair do |name, value|
            headers["#{prefix}#{name}"] = value.to_s
          end
        end

        # With complex headers value in json syntax,
        # base64 encodes value to aviod weird characters
        # causing potential issues in headers
        def apply_json_trait(value)
          Base64.strict_encode64(value)
        end

      end
    end
  end
end

Version data entries

109 entries across 109 versions & 1 rubygems

Version Path
aws-sdk-core-3.88.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.87.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.86.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.85.1 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.85.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.84.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.83.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.82.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.81.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.80.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.79.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.78.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.77.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.76.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.75.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.74.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.73.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.72.1 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.72.0 lib/aws-sdk-core/rest/request/headers.rb
aws-sdk-core-3.71.0 lib/aws-sdk-core/rest/request/headers.rb