Class: Faraday::Utils::Headers

### Home Classes Methods

### In Files

- lib/faraday/utils.rb

### Parent

Hash

### Methods

- ::from
- ::new
- #[]
- #[]=
- #delete
- #fetch
- #has_key?
- #include?
- #key?
- #member?
- #merge
- #merge!
- #parse
- #replace
- #to_hash
- #update

### Class/Module Index

Quicksearch

- Faraday
- Faraday::Adapter
- Faraday::Adapter::EMHttp
- Faraday::Adapter::EMHttp::Manager
- Faraday::Adapter::EMHttp::Options
- Faraday::Adapter::EMSynchrony
- Faraday::Adapter::EMSynchrony::ParallelManager
- Faraday::Adapter::Excon
- Faraday::Adapter::HTTPClient
- Faraday::Adapter::NetHttp
- Faraday::Adapter::NetHttpPersistent
- Faraday::Adapter::Parallelism
- Faraday::Adapter::Patron
- Faraday::Adapter::Rack
- Faraday::Adapter::Test
- Faraday::Adapter::Test::Stub
- Faraday::Adapter::Test::Stubs
- Faraday::Adapter::Test::Stubs::NotFound
- Faraday::Adapter::Typhoeus
- Faraday::AutoloadHelper
- Faraday::ClientError
- Faraday::CompositeReadIO
- Faraday::Connection
- Faraday::ConnectionFailed
- Faraday::ConnectionOptions
- Faraday::Env
- Faraday::Error
- Faraday::FlatParamsEncoder
- Faraday::Middleware
- Faraday::MiddlewareRegistry
- Faraday::MissingDependency
- Faraday::NestedParamsEncoder
- Faraday::Options
- Faraday::ParsingError
- Faraday::ProxyOptions
- Faraday::RackBuilder
- Faraday::RackBuilder::Handler
- Faraday::RackBuilder::StackLocked
- Faraday::Request
- Faraday::Request::Authorization
- Faraday::Request::BasicAuthentication
- Faraday::Request::Instrumentation
- Faraday::Request::Instrumentation::Options
- Faraday::Request::Multipart
- Faraday::Request::Retry
- Faraday::Request::Retry::Options
- Faraday::Request::TokenAuthentication
- Faraday::Request::UrlEncoded
- Faraday::RequestOptions
- Faraday::ResourceNotFound
- Faraday::Response
- Faraday::Response::Logger
- Faraday::Response::Middleware
- Faraday::Response::RaiseError
- Faraday::SSLError
- Faraday::SSLOptions
- Faraday::TimeoutError
- Faraday::Utils
- Faraday::Utils::Headers
- Faraday::Utils::ParamsHash
- EmHttpSslPatch
- Object

No matching classes.

# Faraday::Utils::Headers

Adapted from Rack::Utils::HeaderHash

### Constants

KeyMap

  symbol -> string mapper + cache

### Public Class Methods

from(value) click to toggle source

    # File lib/faraday/utils.rb, line 10
    def self.from(value)
      new(value)
    end

new(hash = nil) click to toggle source

    # File lib/faraday/utils.rb, line 14
    def initialize(hash = nil)
      super()
      @names = {}
      self.update(hash || {})
    end

### Public Instance Methods

[](k) click to toggle source

    # File lib/faraday/utils.rb, line 36
    def [](k)
      k = KeyMap[k]
      super(k) || super(@names[k.downcase])
    end

[]=(k, v) click to toggle source

    # File lib/faraday/utils.rb, line 41
    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 55
    def delete(k)
      k = KeyMap[k]
      if k = @names[k.downcase]
        @names.delete k.downcase
        super(k)
      end
    end

fetch(k, *args, &block) click to toggle source

    # File lib/faraday/utils.rb, line 49
    def fetch(k, *args, &block)
      k = KeyMap[k]
      key = @names.fetch(k.downcase, k)
      super(key, *args, &block)
    end

has_key?(k) click to toggle source
Alias for: include?
include?(k) click to toggle source

    # File lib/faraday/utils.rb, line 63
    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 77
    def merge(other)
      hash = dup
      hash.merge! other
    end

merge!(other) click to toggle source

    # File lib/faraday/utils.rb, line 71
    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 90
    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]
            self[key] << ', ' << value
          else
            self[key] = value
          end
        }
    end

replace(other) click to toggle source

    # File lib/faraday/utils.rb, line 82
    def replace(other)
      clear
      self.update other
      self
    end

to_hash() click to toggle source

    # File lib/faraday/utils.rb, line 88
    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.