Class: Linzer::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/linzer/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(request_data) ⇒ Message

Returns a new instance of Message.



5
6
7
8
# File 'lib/linzer/message.rb', line 5

def initialize(request_data)
  @headers = Hash(request_data[:headers])
  @http = Hash(request_data[:http])
end

Instance Method Details

#[](field_name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/linzer/message.rb', line 18

def [](field_name)
  return @headers[field_name] if !field_name.start_with?("@")

  case field_name
  when "@method" then @http["method"]
  when "@authority" then @http["host"]
  when "@path" then @http["path"]
  else # XXX: improve this and add support for all fields in the RFC
    raise Error.new "Unknown/unsupported field: \"#{field_name}\""
  end
end

#empty?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/linzer/message.rb', line 10

def empty?
  @headers.empty?
end

#header?(header) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/linzer/message.rb', line 14

def header?(header)
  @headers.key?(header)
end