Class: HttpHeader

Inherits:
Hash
  • Object
show all
Defined in:
lib/http_header.rb

Direct Known Subclasses

SSDP::SsdpHeader

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(firstline) ⇒ HttpHeader

Returns a new instance of HttpHeader.



26
27
28
29
# File 'lib/http_header.rb', line 26

def initialize(firstline)
  @name_table = Hash.new
  @firstline = firstline
end

Class Method Details

.read(text) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/http_header.rb', line 73

def HttpHeader.read(text)
  firstline = text.lines[0].strip
  fields = text.lines[1..-1]
  header = HttpHeader.new FirstLine.read(firstline)
  fields.each do |line|
    tokens = line.split ':', 2
    name = tokens[0].strip
    value = tokens[1].strip
    header[name] = value
  end
  header
end

Instance Method Details

#[](key) ⇒ Object



39
40
41
# File 'lib/http_header.rb', line 39

def [](key)
  super _issensitive(key)
end

#[]=(key, value) ⇒ Object



43
44
45
46
# File 'lib/http_header.rb', line 43

def []=(key, value)
  @name_table[_issensitive(key)] = key
  super _issensitive(key), value
end

#firstlineObject



31
32
33
# File 'lib/http_header.rb', line 31

def firstline
  @firstline
end

#org_keysObject



35
36
37
# File 'lib/http_header.rb', line 35

def org_keys
  @name_table.values
end

#to_sObject



52
53
54
55
56
57
58
59
# File 'lib/http_header.rb', line 52

def to_s
  s = "#{firstline}\r\n"
  self.each do |key, value|
    s << "#{@name_table[key]}: #{value}\r\n"
  end
  s << "\r\n"
  return s
end

#to_strObject



61
62
63
# File 'lib/http_header.rb', line 61

def to_str
  self.to_s
end

#update!(hash) ⇒ Object



48
49
50
# File 'lib/http_header.rb', line 48

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