class Aws::Rest::Request::Headers
def apply(http_req, params)
-
params
(Hash
) -- -
http_req
(Seahorse::Client::Http::Request
) --
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
def apply_header_map(headers, ref, values)
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
def apply_header_value(headers, ref, value)
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
def apply_json_trait(value)
base64 encodes value to avoid weird characters
With complex headers value in json syntax,
def apply_json_trait(value) Base64.strict_encode64(value) end
def initialize(rules)
-
rules
(Seahorse::Model::ShapeRef
) --
def initialize(rules) @rules = rules end
def list(headers, ref, values)
def list(headers, ref, values) return if values.nil? member_ref = ref.shape.member values = values.collect do |value| case member_ref.shape when TimestampShape timestamp(member_ref, value).to_s else Seahorse::Util.escape_header_list_string(value.to_s) end end headers[ref.location_name] = values.compact.join(', ') end
def timestamp(ref, value)
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