class Rack::Utils::HeaderHash

:nodoc:
@api private
header when set.
A case-insensitive Hash that preserves the original case of a

def self.[](headers)

Other tags:
    Api: - private
def self.[](headers)
  if headers.is_a?(HeaderHash) && !headers.frozen?
    return headers
  else
    return self.new(headers)
  end
end

def [](k)

def [](k)
  super(k) || super(@names[k.downcase])
end

def []=(k, v)

def []=(k, v)
  canonical = k.downcase.freeze
  delete k if @names[canonical] && @names[canonical] != k # .delete is expensive, don't invoke it unless necessary
  @names[canonical] = k
  super k, v
end

def clear

on clear, we need to clear @names hash
def clear
  super
  @names.clear
end

def delete(k)

def delete(k)
  canonical = k.downcase
  result = super @names.delete(canonical)
  result
end

def each

def each
  super do |k, v|
    yield(k, v.respond_to?(:to_ary) ? v.to_ary.join("\n") : v)
  end
end

def include?(k)

def include?(k)
  super || @names.include?(k.downcase)
end

def initialize(hash = {})

def initialize(hash = {})
  super()
  @names = {}
  hash.each { |k, v| self[k] = v }
end

def initialize_copy(other)

on dup/clone, we need to duplicate @names hash
def initialize_copy(other)
  super
  @names = other.names.dup
end

def merge(other)

def merge(other)
  hash = dup
  hash.merge! other
end

def merge!(other)

def merge!(other)
  other.each { |k, v| self[k] = v }
  self
end

def names

def names
  @names
end

def replace(other)

def replace(other)
  clear
  other.each { |k, v| self[k] = v }
  self
end

def to_hash

def to_hash
  hash = {}
  each { |k, v| hash[k] = v }
  hash
end