A case-insensitive Hash that preserves the original case of a header when set.
# File lib/rack/utils.rb, line 343 def [](k) super(@names[k] ||= @names[k.downcase]) end
# File lib/rack/utils.rb, line 347 def []=(k, v) delete k @names[k] = @names[k.downcase] = k super k, v end
# File lib/rack/utils.rb, line 353 def delete(k) canonical = k.downcase result = super @names.delete(canonical) @names.delete_if { |name,| name.downcase == canonical } result end
# File lib/rack/utils.rb, line 326 def each super do |k, v| yield(k, v.respond_to?(:to_ary) ? v.to_ary.join("\n") : v) end end
# File lib/rack/utils.rb, line 360 def include?(k) @names.include?(k) || @names.include?(k.downcase) end
# File lib/rack/utils.rb, line 373 def merge(other) hash = dup hash.merge! other end
# File lib/rack/utils.rb, line 368 def merge!(other) other.each { |k, v| self[k] = v } self end
# File lib/rack/utils.rb, line 378 def replace(other) clear other.each { |k, v| self[k] = v } self end
# File lib/rack/utils.rb, line 332 def to_hash inject({}) do |hash, (k,v)| if v.respond_to? :to_ary hash[k] = v.to_ary.join("\n") else hash[k] = v end hash end end
# File lib/rack/utils.rb, line 316 def self.new(hash={}) HeaderHash === hash ? hash : super(hash) end
# File lib/rack/utils.rb, line 320 def initialize(hash={}) super() @names = {} hash.each { |k, v| self[k] = v } end