class Seahorse::Client::Http::Headers
Provides a Hash-like interface for HTTP headers. Header names are treated indifferently as lower-cased strings. Header values are cast to strings.
headers = Http::Headers.new headers['Content-Length'] = 100 headers[:Authorization] = 'Abc' headers.keys #=> ['content-length', 'authorization'] headers.values #=> ['100', 'Abc']
You can get the header values as a vanilla hash by calling {#to_h}:
headers.to_h #=> { 'content-length' => '100', 'authorization' => 'Abc' }
Public Class Methods
new(headers = {})
click to toggle source
@api private
# File lib/seahorse/client/http/headers.rb, line 29 def initialize(headers = {}) @data = {} headers.each_pair do |key, value| self[key] = value end end
Public Instance Methods
[](key)
click to toggle source
@param [String] key @return [String]
# File lib/seahorse/client/http/headers.rb, line 38 def [](key) @data[key.to_s.downcase] end
[]=(key, value)
click to toggle source
@param [String] key @param [String] value
# File lib/seahorse/client/http/headers.rb, line 44 def []=(key, value) @data[key.to_s.downcase] = value.to_s end
clear()
click to toggle source
# File lib/seahorse/client/http/headers.rb, line 62 def clear @data = {} end
delete(key)
click to toggle source
@param [String] key
# File lib/seahorse/client/http/headers.rb, line 58 def delete(key) @data.delete(key.to_s.downcase) end
each() { |key, value| ... }
click to toggle source
@yield [key, value] @yieldparam [String] key @yieldparam [String] value @return [nil]
# File lib/seahorse/client/http/headers.rb, line 85 def each(&block) if block_given? @data.each_pair do |key, value| yield(key, value) end nil else @data.enum_for(:each) end end
Also aliased as: each_pair
inspect()
click to toggle source
@api private
# File lib/seahorse/client/http/headers.rb, line 111 def inspect @data.inspect end
key?(key)
click to toggle source
@return [Boolean] Returns `true` if the header is set.
# File lib/seahorse/client/http/headers.rb, line 98 def key?(key) @data.key?(key.to_s.downcase) end
keys()
click to toggle source
@return [Array<String>]
# File lib/seahorse/client/http/headers.rb, line 67 def keys @data.keys end
to_hash()
click to toggle source
@return [Hash]
# File lib/seahorse/client/http/headers.rb, line 105 def to_hash @data.dup end
Also aliased as: to_h
update(headers)
click to toggle source
@param [Hash] headers @return [Headers]
# File lib/seahorse/client/http/headers.rb, line 50 def update(headers) headers.each_pair do |k, v| self[k] = v end self end
values()
click to toggle source
@return [Array<String>]
# File lib/seahorse/client/http/headers.rb, line 72 def values @data.values end
values_at(*keys)
click to toggle source
@return [Array<String>]
# File lib/seahorse/client/http/headers.rb, line 77 def values_at(*keys) @data.values_at(*keys.map{ |key| key.to_s.downcase }) end