Class: HttpParser::Parser
- Inherits:
-
Object
- Object
- HttpParser::Parser
- Defined in:
- lib/http-parser/parser.rb
Defined Under Namespace
Classes: Callback, DataCallback
Constant Summary collapse
- CALLBACKS =
[ :on_message_begin, :on_url, :on_status, :on_header_field, :on_header_value, :on_headers_complete, :on_body, :on_message_complete, :on_chunk_header, :on_chunk_complete ]
Class Method Summary collapse
-
.new_instance(&block) ⇒ Object
Returns a new request/response instance variable.
Instance Method Summary collapse
-
#initialize(callback_obj = nil) {|_self| ... } ⇒ Parser
constructor
Initializes the Parser instance.
-
#on_body {|instance, body| ... } ⇒ Object
Registers an ‘on_body` callback.
-
#on_chunk_complete {|instance| ... } ⇒ Object
Registers an ‘on_chunk_complete` callback.
-
#on_chunk_header {|instance| ... } ⇒ Object
Registers an ‘on_chunk_header` callback.
-
#on_header_field {|instance, field| ... } ⇒ Object
Registers an ‘on_header_field` callback.
-
#on_header_value {|instance, value| ... } ⇒ Object
Registers an ‘on_header_value` callback.
-
#on_headers_complete {|instance| ... } ⇒ Object
Registers an ‘on_headers_complete` callback.
-
#on_message_begin {|instance| ... } ⇒ Object
Registers an ‘on_message_begin` callback.
-
#on_message_complete {|instance| ... } ⇒ Object
Registers an ‘on_message_begin` callback.
-
#on_status {|instance| ... } ⇒ Object
Registers an ‘on_status_complete` callback.
-
#on_url {|instance, url| ... } ⇒ Object
Registers an ‘on_url` callback.
-
#parse(inst, data) ⇒ Boolean
Parses data.
Constructor Details
#initialize(callback_obj = nil) {|_self| ... } ⇒ Parser
Initializes the Parser instance.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/http-parser/parser.rb', line 21 def initialize(callback_obj = nil) @settings = ::HttpParser::Settings.new @callbacks = {} # so GC doesn't clean them up on java if not callback_obj.nil? CALLBACKS.each do |callback| self.__send__(callback, &callback_obj.method(callback)) if callback_obj.respond_to? callback end end yield self if block_given? end |
Class Method Details
.new_instance(&block) ⇒ Object
Returns a new request/response instance variable
13 14 15 |
# File 'lib/http-parser/parser.rb', line 13 def self.new_instance(&block) ::HttpParser::Instance.new(&block) end |
Instance Method Details
#on_body {|instance, body| ... } ⇒ Object
Registers an ‘on_body` callback.
158 159 160 161 162 |
# File 'lib/http-parser/parser.rb', line 158 def on_body(&block) cb = DataCallback.new(&block) @callbacks[:on_body] = cb @settings[:on_body] = cb end |
#on_chunk_complete {|instance| ... } ⇒ Object
Registers an ‘on_chunk_complete` callback.
203 204 205 206 207 |
# File 'lib/http-parser/parser.rb', line 203 def on_chunk_complete(&block) cb = Callback.new(&block) @callbacks[:on_message_complete] = cb @settings[:on_message_complete] = cb end |
#on_chunk_header {|instance| ... } ⇒ Object
Registers an ‘on_chunk_header` callback.
188 189 190 191 192 |
# File 'lib/http-parser/parser.rb', line 188 def on_chunk_header(&block) cb = Callback.new(&block) @callbacks[:on_message_complete] = cb @settings[:on_message_complete] = cb end |
#on_header_field {|instance, field| ... } ⇒ Object
Registers an ‘on_header_field` callback.
100 101 102 103 104 |
# File 'lib/http-parser/parser.rb', line 100 def on_header_field(&block) cb = DataCallback.new(&block) @callbacks[:on_header_field] = cb @settings[:on_header_field] = cb end |
#on_header_value {|instance, value| ... } ⇒ Object
Registers an ‘on_header_value` callback.
121 122 123 124 125 |
# File 'lib/http-parser/parser.rb', line 121 def on_header_value(&block) cb = DataCallback.new(&block) @callbacks[:on_header_value] = cb @settings[:on_header_value] = cb end |
#on_headers_complete {|instance| ... } ⇒ Object
Registers an ‘on_headers_complete` callback.
136 137 138 139 140 |
# File 'lib/http-parser/parser.rb', line 136 def on_headers_complete(&block) cb = Callback.new(&block) @callbacks[:on_headers_complete] = cb @settings[:on_headers_complete] = cb end |
#on_message_begin {|instance| ... } ⇒ Object
Registers an ‘on_message_begin` callback.
43 44 45 46 47 |
# File 'lib/http-parser/parser.rb', line 43 def (&block) cb = Callback.new(&block) @callbacks[:on_message_begin] = cb @settings[:on_message_begin] = cb end |
#on_message_complete {|instance| ... } ⇒ Object
Registers an ‘on_message_begin` callback.
173 174 175 176 177 |
# File 'lib/http-parser/parser.rb', line 173 def (&block) cb = Callback.new(&block) @callbacks[:on_message_complete] = cb @settings[:on_message_complete] = cb end |
#on_status {|instance| ... } ⇒ Object
Registers an ‘on_status_complete` callback.
79 80 81 82 83 |
# File 'lib/http-parser/parser.rb', line 79 def on_status(&block) cb = DataCallback.new(&block) @callbacks[:on_status] = cb @settings[:on_status] = cb end |
#on_url {|instance, url| ... } ⇒ Object
Registers an ‘on_url` callback.
64 65 66 67 68 |
# File 'lib/http-parser/parser.rb', line 64 def on_url(&block) cb = DataCallback.new(&block) @callbacks[:on_url] = cb @settings[:on_url] = cb end |
#parse(inst, data) ⇒ Boolean
Parses data.
221 222 223 224 |
# File 'lib/http-parser/parser.rb', line 221 def parse(inst, data) ::HttpParser.http_parser_execute(inst, @settings, data, data.length) return inst.error? end |