class Rack::Headers
Rack::Headers
is a Hash subclass that downcases all keys. It’s designed to be used by rack applications that don’t implement the Rack
3 SPEC (by using non-lowercase response header keys), automatically handling the downcasing of keys.
Public Class Methods
Source
# File lib/rack/headers.rb, line 7 def self.[](*items) if items.length % 2 != 0 if items.length == 1 && items.first.is_a?(Hash) new.merge!(items.first) else raise ArgumentError, "odd number of arguments for Rack::Headers" end else hash = new loop do break if items.length == 0 key = items.shift value = items.shift hash[key] = value end hash end end
Public Instance Methods
Source
# File lib/rack/headers.rb, line 26 def [](key) super(downcase_key(key)) end
Calls superclass method
Source
# File lib/rack/headers.rb, line 30 def []=(key, value) super(key.downcase.freeze, value) end
Calls superclass method
Also aliased as: store
Source
# File lib/rack/headers.rb, line 35 def assoc(key) super(downcase_key(key)) end
Calls superclass method
Source
# File lib/rack/headers.rb, line 39 def compare_by_identity raise TypeError, "Rack::Headers cannot compare by identity, use regular Hash" end
Source
# File lib/rack/headers.rb, line 43 def delete(key) super(downcase_key(key)) end
Calls superclass method
Source
# File lib/rack/headers.rb, line 47 def dig(key, *a) super(downcase_key(key), *a) end
Calls superclass method
Source
# File lib/rack/headers.rb, line 143 def except(*a) super(*a.map!{|key| downcase_key(key)}) end
:nocov:
Calls superclass method
Source
# File lib/rack/headers.rb, line 51 def fetch(key, *default, &block) key = downcase_key(key) super end
Calls superclass method
Source
# File lib/rack/headers.rb, line 56 def fetch_values(*a) super(*a.map!{|key| downcase_key(key)}) end
Calls superclass method
Source
# File lib/rack/headers.rb, line 60 def has_key?(key) super(downcase_key(key)) end
Calls superclass method
Source
# File lib/rack/headers.rb, line 67 def invert hash = self.class.new each{|key, value| hash[value] = key} hash end
Source
# File lib/rack/headers.rb, line 73 def merge(hash, &block) dup.merge!(hash, &block) end
Source
# File lib/rack/headers.rb, line 77 def reject(&block) hash = dup hash.reject!(&block) hash end
Source
# File lib/rack/headers.rb, line 88 def select(&block) hash = dup hash.select!(&block) hash end
Source
# File lib/rack/headers.rb, line 121 def slice(*a) h = self.class.new a.each{|k| h[k] = self[k] if has_key?(k)} h end
:nocov:
Source
# File lib/rack/headers.rb, line 127 def transform_keys(&block) dup.transform_keys!(&block) end
Source
# File lib/rack/headers.rb, line 131 def transform_keys! hash = self.class.new each do |k, v| hash[yield k] = v end replace(hash) end
Source
# File lib/rack/headers.rb, line 98 def transform_values(&block) dup.transform_values!(&block) end
Source
# File lib/rack/headers.rb, line 102 def update(hash, &block) hash.each do |key, value| self[key] = if block_given? && include?(key) block.call(key, self[key], value) else value end end self end
Also aliased as: merge!
Source
# File lib/rack/headers.rb, line 114 def values_at(*keys) keys.map{|key| self[key]} end