class Aws::Rest::Request::Headers
Public Class Methods
new(rules)
click to toggle source
@param [Seahorse::Model::ShapeRef] rules
# File lib/aws-sdk-core/rest/request/headers.rb, line 14 def initialize(rules) @rules = rules end
Public Instance Methods
apply(http_req, params)
click to toggle source
@param [Seahorse::Client::Http::Request] http_req @param [Hash] params
# File lib/aws-sdk-core/rest/request/headers.rb, line 20 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 Instance Methods
apply_header_map(headers, ref, values)
click to toggle source
# File lib/aws-sdk-core/rest/request/headers.rb, line 64 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
apply_header_value(headers, ref, value)
click to toggle source
# File lib/aws-sdk-core/rest/request/headers.rb, line 33 def apply_header_value(headers, ref, value) value = apply_json_trait(value) if ref['jsonvalue'] case ref.shape when TimestampShape then headers[ref.location_name] = timestamp(ref, value) when ListShape then list(headers, ref, value) else headers[ref.location_name] = value.to_s end end
apply_json_trait(value)
click to toggle source
With complex headers value in json syntax, base64 encodes value to avoid weird characters causing potential issues in headers
# File lib/aws-sdk-core/rest/request/headers.rb, line 74 def apply_json_trait(value) Base64.strict_encode64(value) end
escape_header_list_string(s)
click to toggle source
# File lib/aws-sdk-core/rest/request/headers.rb, line 60 def escape_header_list_string(s) (s.include?('"') || s.include?(",")) ? "\"#{s.gsub('"', '\"')}\"" : s end
list(headers, ref, value)
click to toggle source
# File lib/aws-sdk-core/rest/request/headers.rb, line 52 def list(headers, ref, value) return if !value || value.empty? headers[ref.location_name] = value .compact .map { |s| escape_header_list_string(s.to_s) } .join(",") end
timestamp(ref, value)
click to toggle source
# File lib/aws-sdk-core/rest/request/headers.rb, line 42 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