Class: Fluent::Plugin::GroongaInput::HTTPInput::ResponseHandler
- Inherits:
-
Object
- Object
- Fluent::Plugin::GroongaInput::HTTPInput::ResponseHandler
- Defined in:
- lib/fluent/plugin/in_groonga.rb
Instance Method Summary collapse
- #<<(chunk) ⇒ Object
-
#initialize(handler, input) ⇒ ResponseHandler
constructor
A new instance of ResponseHandler.
- #on_body(chunk) ⇒ Object
- #on_headers_complete(headers) ⇒ Object
- #on_message_begin ⇒ Object
- #on_message_complete ⇒ Object
Constructor Details
#initialize(handler, input) ⇒ ResponseHandler
Returns a new instance of ResponseHandler.
342 343 344 345 346 |
# File 'lib/fluent/plugin/in_groonga.rb', line 342 def initialize(handler, input) @handler = handler @input = input @parser = Http::Parser.new(self) end |
Instance Method Details
#<<(chunk) ⇒ Object
348 349 350 |
# File 'lib/fluent/plugin/in_groonga.rb', line 348 def <<(chunk) @parser << chunk end |
#on_body(chunk) ⇒ Object
366 367 368 |
# File 'lib/fluent/plugin/in_groonga.rb', line 366 def on_body(chunk) @body << chunk end |
#on_headers_complete(headers) ⇒ Object
357 358 359 360 361 362 363 364 |
# File 'lib/fluent/plugin/in_groonga.rb', line 357 def on_headers_complete(headers) headers.each do |name, value| case name when /\AContent-Type\z/i @content_type = value end end end |
#on_message_begin ⇒ Object
352 353 354 355 |
# File 'lib/fluent/plugin/in_groonga.rb', line 352 def @body = "" @content_type = nil end |
#on_message_complete ⇒ Object
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/fluent/plugin/in_groonga.rb', line 370 def return if @parser.status_code == 100 response = nil case @content_type when /\Aapplication\/json\z/i begin response = JSON.parse(@body) rescue JSON::ParserError @input.log.warn("[input][groonga][response][warn] " + "failed to parse response JSON:", :error => "#{$!.class}: #{$!}", :json => @body) end when /\Aapplication\/x-msgpack\z/i begin response = MessagePack.unpack(@body) rescue MessagePack::UnpackError, EOFError @input.log.warn("[input][groonga][response][warn] " + "failed to parse response MessagePack", :error => "#{$!.class}: #{$!}", :msgpack => @body) end when /\Atext\/x-groonga-command-list\z/i response = @body end @handler.on_response_complete(response) end |