Class: Fluent::Plugin::GroongaInput::HTTPInput::RequestHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_groonga.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, repeater) ⇒ RequestHandler

Returns a new instance of RequestHandler.



286
287
288
289
290
# File 'lib/fluent/plugin/in_groonga.rb', line 286

def initialize(input, repeater)
  @input = input
  @repeater = repeater
  @parser = Http::Parser.new(self)
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



284
285
286
# File 'lib/fluent/plugin/in_groonga.rb', line 284

def command
  @command
end

#paramsObject (readonly)

Returns the value of attribute params.



285
286
287
# File 'lib/fluent/plugin/in_groonga.rb', line 285

def params
  @params
end

Instance Method Details

#<<(chunk) ⇒ Object



292
293
294
# File 'lib/fluent/plugin/in_groonga.rb', line 292

def <<(chunk)
  @parser << chunk
end

#on_body(chunk) ⇒ Object



320
321
322
323
# File 'lib/fluent/plugin/in_groonga.rb', line 320

def on_body(chunk)
  @body << chunk
  @repeater.write(chunk)
end

#on_headers_complete(headers) ⇒ Object



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/fluent/plugin/in_groonga.rb', line 302

def on_headers_complete(headers)
  method = @parser.http_method
  url = @parser.request_url
  http_version = @parser.http_version.join(".")
  @repeater.write("#{method} #{url} HTTP/#{http_version}\r\n")
  headers.each do |name, value|
    case name
    when /\AHost\z/i
      real_host = @input.real_host
      real_port = @input.real_port
      @repeater.write("#{name}: #{real_host}:#{real_port}\r\n")
    else
      @repeater.write("#{name}: #{value}\r\n")
    end
  end
  @repeater.write("\r\n")
end

#on_message_beginObject



296
297
298
299
300
# File 'lib/fluent/plugin/in_groonga.rb', line 296

def on_message_begin
  @body = ""
  @command = nil
  @params = nil
end

#on_message_completeObject



325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/fluent/plugin/in_groonga.rb', line 325

def on_message_complete
  uri = URI.parse(@parser.request_url)
  params = WEBrick::HTTPUtils.parse_query(uri.query)
  path_info = uri.path
  case path_info
  when /\A\/d\//
    command = $POSTMATCH
    if command == "load"
      params["values"] = @body unless @body.empty?
    end
    @command = command
    @params = params
  end
end