Class: Requests::Http2Response

Inherits:
Object
  • Object
show all
Defined in:
lib/requests/http2.rb

Instance Method Summary collapse

Constructor Details

#initialize(header_pairs, body) ⇒ Http2Response

Returns a new instance of Http2Response.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/requests/http2.rb', line 12

def initialize(header_pairs, body)
  @status = nil
  @fields = Hash.new { |h, k| h[k] = [] }
  @headers = CIHash.new
  header_pairs.each do |k, v|
    if k == ':status'
      @status = v
    else
      @fields[k.downcase] << v
      @headers[k] = v
    end
  end
  @body = body
end

Instance Method Details

#[](k) ⇒ Object



32
33
34
# File 'lib/requests/http2.rb', line 32

def [](k)
  @headers[k]
end

#bodyObject



43
44
45
# File 'lib/requests/http2.rb', line 43

def body
  @body
end

#codeObject



26
27
28
# File 'lib/requests/http2.rb', line 26

def code
  @status
end

#each_headerObject



35
36
37
38
# File 'lib/requests/http2.rb', line 35

def each_header
  return enum_for(:each_header) unless block_given?
  @headers.each { |k, v| yield k, v }
end

#get_fields(name) ⇒ Object



39
40
41
42
# File 'lib/requests/http2.rb', line 39

def get_fields(name)
  f = @fields[name.to_s.downcase]
  f.empty? ? nil : f
end

#messageObject



29
30
31
# File 'lib/requests/http2.rb', line 29

def message
  (Requests::STATUS_CODES[@status.to_i] || :unknown).to_s.split('_').map(&:capitalize).join(' ')
end