Class: HTTP::Headers

Inherits:
Object show all
Defined in:
lib/http_client/jruby/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(native_response) ⇒ Headers

Returns a new instance of Headers.



29
30
31
# File 'lib/http_client/jruby/response.rb', line 29

def initialize(native_response)
  @native_response = native_response
end

Instance Method Details

#[](header_name) ⇒ Object



33
34
35
# File 'lib/http_client/jruby/response.rb', line 33

def [](header_name)
  @native_response.get_headers(header_name).map{|h| h.get_value}.join(", ")
end

#eachObject



49
50
51
52
53
# File 'lib/http_client/jruby/response.rb', line 49

def each
  @native_response.header_iterator.each do |h|
    yield h.get_name, h.get_value
  end
end

#to_hashObject



41
42
43
44
45
46
47
# File 'lib/http_client/jruby/response.rb', line 41

def to_hash
  hash = {}
  each do |name, value|
    hash[name] = hash[name] ? hash[name] + ", #{value}" : value
  end
  hash
end

#to_sObject



37
38
39
# File 'lib/http_client/jruby/response.rb', line 37

def to_s
  @native_response.get_all_headers.map(&:to_s).join("\n")
end