You are viewing documentation for version 3 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: Aws::Rest::Response::Headers

Inherits:
Object
  • Object
show all
Includes:
Seahorse::Model::Shapes
Defined in:
gems/aws-sdk-core/lib/aws-sdk-core/rest/response/headers.rb

Instance Method Summary collapse

Constructor Details

#initialize(rules) ⇒ Headers

Returns a new instance of Headers

Parameters:

  • rules (Seahorse::Model::ShapeRef)


13
14
15
# File 'gems/aws-sdk-core/lib/aws-sdk-core/rest/response/headers.rb', line 13

def initialize(rules)
  @rules = rules
end

Instance Method Details

#apply(http_resp, target) ⇒ Object

Parameters:



19
20
21
22
23
24
25
26
27
# File 'gems/aws-sdk-core/lib/aws-sdk-core/rest/response/headers.rb', line 19

def apply(http_resp, target)
  headers = http_resp.headers
  @rules.shape.members.each do |name, ref|
    case ref.location
    when 'header' then extract_header_value(headers, name, ref, target)
    when 'headers' then extract_header_map(headers, name, ref, target)
    end
  end
end

#cast_value(ref, value) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'gems/aws-sdk-core/lib/aws-sdk-core/rest/response/headers.rb', line 35

def cast_value(ref, value)
  value = extract_json_trait(value) if ref['jsonvalue']
  case ref.shape
  when StringShape then value
  when IntegerShape then value.to_i
  when FloatShape then value.to_f
  when BooleanShape then value == 'true'
  when TimestampShape
    if value =~ /\d+(\.\d*)/
      Time.at(value.to_f)
    else
      begin
        Time.parse(value)
      rescue
        nil
      end
    end
  else raise "unsupported shape #{ref.shape.class}"
  end
end

#extract_header_map(headers, name, ref, data) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'gems/aws-sdk-core/lib/aws-sdk-core/rest/response/headers.rb', line 56

def extract_header_map(headers, name, ref, data)
  data[name] = {}
  prefix = ref.location_name || ''
  headers.each do |header_name, header_value|
    if match = header_name.match(/^#{prefix}(.+)/i)
      data[name][match[1]] = header_value
    end
  end
end

#extract_header_value(headers, name, ref, data) ⇒ Object



29
30
31
32
33
# File 'gems/aws-sdk-core/lib/aws-sdk-core/rest/response/headers.rb', line 29

def extract_header_value(headers, name, ref, data)
  if headers.key?(ref.location_name)
    data[name] = cast_value(ref, headers[ref.location_name])
  end
end

#extract_json_trait(value) ⇒ Object



66
67
68
# File 'gems/aws-sdk-core/lib/aws-sdk-core/rest/response/headers.rb', line 66

def extract_json_trait(value)
  JSON.parse(Base64.decode64(value))
end