Class: Motion::HTTP::Headers

Inherits:
Object
  • Object
show all
Defined in:
lib/common/http/headers.rb

Instance Method Summary collapse

Constructor Details

#initialize(headers = {}) ⇒ Headers

Returns a new instance of Headers.



4
5
6
# File 'lib/common/http/headers.rb', line 4

def initialize(headers = {})
  @headers = headers
end

Instance Method Details

#[](key) ⇒ Object



24
25
26
# File 'lib/common/http/headers.rb', line 24

def [](key)
  @headers[key.downcase]
end

#add(key, value) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/common/http/headers.rb', line 12

def add(key, value)
  key = key.downcase
  if @headers[key] && !@headers[key].is_a?(Array)
    @headers[key] = [@headers[key]]
  end
  @headers[key] << value
end

#each(&block) ⇒ Object



20
21
22
# File 'lib/common/http/headers.rb', line 20

def each(&block)
  @headers.each(&block)
end

#set(key, value) ⇒ Object



8
9
10
# File 'lib/common/http/headers.rb', line 8

def set(key, value)
  @headers[key.downcase] = value
end