Class: Invoker::Power::HttpParser

Inherits:
Object
  • Object
show all
Defined in:
lib/invoker/power/http_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(protocol) ⇒ HttpParser

Returns a new instance of HttpParser.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/invoker/power/http_parser.rb', line 6

def initialize(protocol)
  @protocol = protocol
  @parser = HTTP::Parser.new
  @header = {}
  initialize_message_content
  parser.on_headers_complete { complete_headers_received }
  parser.on_header_field { |field_name| @last_key = field_name }
  parser.on_header_value { |field_value| header_value_received(field_value) }

  parser.on_message_complete { complete_message_received }
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/invoker/power/http_parser.rb', line 4

def host
  @host
end

#parserObject

Returns the value of attribute parser.



4
5
6
# File 'lib/invoker/power/http_parser.rb', line 4

def parser
  @parser
end

#protocolObject

Returns the value of attribute protocol.



4
5
6
# File 'lib/invoker/power/http_parser.rb', line 4

def protocol
  @protocol
end

Instance Method Details

#<<(data) ⇒ Object



38
39
40
41
# File 'lib/invoker/power/http_parser.rb', line 38

def << data
  @full_message.write(data)
  parser << data
end

#header_value_received(value) ⇒ Object



23
24
25
# File 'lib/invoker/power/http_parser.rb', line 23

def header_value_received(value)
  @header[@last_key] = value
end

#on_headers_complete(&block) ⇒ Object

define a callback for invoking when complete header is parsed



19
20
21
# File 'lib/invoker/power/http_parser.rb', line 19

def on_headers_complete(&block)
  @on_headers_complete_callback = block
end

#on_message_complete(&block) ⇒ Object

define a callback to invoke when a full http message is received



28
29
30
# File 'lib/invoker/power/http_parser.rb', line 28

def on_message_complete(&block)
  @on_message_complete_callback = block
end

#resetObject



32
33
34
35
36
# File 'lib/invoker/power/http_parser.rb', line 32

def reset
  @header = {}
  initialize_message_content
  parser.reset
end