Class: Invoker::Power::HttpParser
- Inherits:
-
Object
- Object
- Invoker::Power::HttpParser
- Defined in:
- lib/invoker/power/http_parser.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #header_value_received(value) ⇒ Object
-
#initialize(protocol) ⇒ HttpParser
constructor
A new instance of HttpParser.
-
#on_headers_complete(&block) ⇒ Object
define a callback for invoking when complete header is parsed.
-
#on_message_complete(&block) ⇒ Object
define a callback to invoke when a full http message is received.
- #reset ⇒ Object
Constructor Details
#initialize(protocol) ⇒ 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 = {} 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. { } end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/invoker/power/http_parser.rb', line 4 def host @host end |
#parser ⇒ Object
Returns the value of attribute parser.
4 5 6 |
# File 'lib/invoker/power/http_parser.rb', line 4 def parser @parser end |
#protocol ⇒ Object
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 (&block) @on_message_complete_callback = block end |
#reset ⇒ Object
32 33 34 35 36 |
# File 'lib/invoker/power/http_parser.rb', line 32 def reset @header = {} parser.reset end |