A case-insensitive Hash that preserves the original case of a header when set.
# File lib/rack/utils.rb, line 477 def self.new(hash={}) HeaderHash === hash ? hash : super(hash) end
# File lib/rack/utils.rb, line 481 def initialize(hash={}) super() @names = {} hash.each { |k, v| self[k] = v } end
# File lib/rack/utils.rb, line 499 def [](k) super(k) || super(@names[k.downcase]) end
# File lib/rack/utils.rb, line 503 def []=(k, v) canonical = k.downcase delete k if @names[canonical] && @names[canonical] != k # .delete is expensive, don't invoke it unless necessary @names[k] = @names[canonical] = k super k, v end
# File lib/rack/utils.rb, line 510 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 487 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 517 def include?(k) @names.include?(k) || @names.include?(k.downcase) end
# File lib/rack/utils.rb, line 530 def merge(other) hash = dup hash.merge! other end
# File lib/rack/utils.rb, line 525 def merge!(other) other.each { |k, v| self[k] = v } self end
# File lib/rack/utils.rb, line 535 def replace(other) clear other.each { |k, v| self[k] = v } self end
# File lib/rack/utils.rb, line 493 def to_hash hash = {} each { |k,v| hash[k] = v } hash end