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.



274
275
276
277
278
# File 'lib/fluent/plugin/in_groonga.rb', line 274

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.



272
273
274
# File 'lib/fluent/plugin/in_groonga.rb', line 272

def command
  @command
end

#paramsObject (readonly)

Returns the value of attribute params.



273
274
275
# File 'lib/fluent/plugin/in_groonga.rb', line 273

def params
  @params
end

Instance Method Details

#<<(chunk) ⇒ Object



280
281
282
# File 'lib/fluent/plugin/in_groonga.rb', line 280

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

#on_body(chunk) ⇒ Object



308
309
310
311
# File 'lib/fluent/plugin/in_groonga.rb', line 308

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

#on_headers_complete(headers) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/fluent/plugin/in_groonga.rb', line 290

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



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

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

#on_message_completeObject



313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/fluent/plugin/in_groonga.rb', line 313

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