Class: Fluent::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.



305
306
307
308
309
# File 'lib/fluent/plugin/in_groonga.rb', line 305

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.



303
304
305
# File 'lib/fluent/plugin/in_groonga.rb', line 303

def command
  @command
end

#paramsObject (readonly)

Returns the value of attribute params.



304
305
306
# File 'lib/fluent/plugin/in_groonga.rb', line 304

def params
  @params
end

Instance Method Details

#<<(chunk) ⇒ Object



311
312
313
# File 'lib/fluent/plugin/in_groonga.rb', line 311

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

#on_body(chunk) ⇒ Object



339
340
341
342
# File 'lib/fluent/plugin/in_groonga.rb', line 339

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

#on_headers_complete(headers) ⇒ Object



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

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



315
316
317
318
319
# File 'lib/fluent/plugin/in_groonga.rb', line 315

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

#on_message_completeObject



344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/fluent/plugin/in_groonga.rb', line 344

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