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
Source
# File lib/seahorse/client/http/headers.rb, line 31 def initialize(headers = {}) @data = {} headers.each_pair do |key, value| self[key] = value end end
@api private
Public Instance Methods
Source
# File lib/seahorse/client/http/headers.rb, line 40 def [](key) @data[key.to_s.downcase] end
@param [String] key @return [String]
Source
# File lib/seahorse/client/http/headers.rb, line 46 def []=(key, value) @data[key.to_s.downcase] = value.to_s end
@param [String] key @param [String] value
Source
# File lib/seahorse/client/http/headers.rb, line 60 def delete(key) @data.delete(key.to_s.downcase) end
@param [String] key
Source
# File lib/seahorse/client/http/headers.rb, line 87 def each(&block) if block_given? @data.each_pair do |key, value| yield(key, value) end nil else @data.enum_for(:each) end end
@yield [key, value] @yieldparam [String] key @yieldparam [String] value @return [nil]
Also aliased as: each_pair
Source
# File lib/seahorse/client/http/headers.rb, line 113 def inspect @data.inspect end
@api private
Source
# File lib/seahorse/client/http/headers.rb, line 100 def key?(key) @data.key?(key.to_s.downcase) end
@return [Boolean] Returns ‘true` if the header is set.
Source
# File lib/seahorse/client/http/headers.rb, line 69 def keys @data.keys end
@return [Array<String>]
Source
# File lib/seahorse/client/http/headers.rb, line 107 def to_hash @data.dup end
@return [Hash]
Also aliased as: to_h
Source
# File lib/seahorse/client/http/headers.rb, line 52 def update(headers) headers.each_pair do |k, v| self[k] = v end self end
@param [Hash] headers @return [Headers]
Source
# File lib/seahorse/client/http/headers.rb, line 74 def values @data.values end
@return [Array<String>]
Source
# File lib/seahorse/client/http/headers.rb, line 79 def values_at(*keys) @data.values_at(*keys.map{ |key| key.to_s.downcase }) end
@return [Array<String>]