Parent

Faraday::Utils::Headers

Adapted from Rack::Utils::HeaderHash

Constants

KeyMap

symbol -> string mapper + cache

Public Class Methods

new(hash={}) click to toggle source
# File lib/faraday/utils.rb, line 9
def initialize(hash={})
  super()
  @names = {}
  self.update hash
end

Public Instance Methods

[](k) click to toggle source
# File lib/faraday/utils.rb, line 26
def [](k)
  k = KeyMap[k]
  super(k) || super(@names[k.downcase])
end
[]=(k, v) click to toggle source
# File lib/faraday/utils.rb, line 31
def []=(k, v)
  k = KeyMap[k]
  k = (@names[k.downcase] ||= k)
  # join multiple values with a comma
  v = v.to_ary.join(', ') if v.respond_to? :to_ary
  super k, v
end
delete(k) click to toggle source
# File lib/faraday/utils.rb, line 39
def delete(k)
  k = KeyMap[k]
  if k = @names[k.downcase]
    @names.delete k.downcase
    super k
  end
end
has_key?(k) click to toggle source
Alias for: include?
include?(k) click to toggle source
# File lib/faraday/utils.rb, line 47
def include?(k)
  @names.include? k.downcase
end
Also aliased as: has_key?, member?, key?
key?(k) click to toggle source
Alias for: include?
member?(k) click to toggle source
Alias for: include?
merge(other) click to toggle source
# File lib/faraday/utils.rb, line 61
def merge(other)
  hash = dup
  hash.merge! other
end
merge!(other) click to toggle source
# File lib/faraday/utils.rb, line 55
def merge!(other)
  other.each { |k, v| self[k] = v }
  self
end
Also aliased as: update
parse(header_string) click to toggle source
# File lib/faraday/utils.rb, line 74
def parse(header_string)
  return unless header_string && !header_string.empty?
  header_string.split(/\r\n/).
    tap  { |a| a.shift if a.first.index('HTTP/') == 0 }. # drop the HTTP status line
    map  { |h| h.split(/:\s+/, 2) }.reject { |p| p[0].nil? }. # split key and value, ignore blank lines
    each { |key, value|
      # join multiple values with a comma
      if self[key] then self[key] << ', ' << value
      else self[key] = value
      end
    }
end
replace(other) click to toggle source
# File lib/faraday/utils.rb, line 66
def replace(other)
  clear
  self.update other
  self
end
to_hash() click to toggle source
# File lib/faraday/utils.rb, line 72
def to_hash() ::Hash.new.update(self) end
update(other) click to toggle source
Alias for: merge!

[Validate]

Generated with the Darkfish Rdoc Generator 2.