Class: Fluent::GroongaInput::HTTPInput::Handler
- Inherits:
-
Coolio::Socket
- Object
- Coolio::Socket
- Fluent::GroongaInput::HTTPInput::Handler
- Defined in:
- lib/fluent/plugin/in_groonga.rb
Instance Method Summary collapse
-
#initialize(socket, input) ⇒ Handler
constructor
A new instance of Handler.
- #on_body(chunk) ⇒ Object
- #on_connect ⇒ Object
- #on_headers_complete(headers) ⇒ Object
- #on_message_begin ⇒ Object
- #on_message_complete ⇒ Object
- #on_read(data) ⇒ Object
Constructor Details
#initialize(socket, input) ⇒ Handler
Returns a new instance of Handler.
188 189 190 191 |
# File 'lib/fluent/plugin/in_groonga.rb', line 188 def initialize(socket, input) super(socket) @input = input end |
Instance Method Details
#on_body(chunk) ⇒ Object
232 233 234 235 |
# File 'lib/fluent/plugin/in_groonga.rb', line 232 def on_body(chunk) @body << chunk @repeater.write(chunk) end |
#on_connect ⇒ Object
193 194 195 196 |
# File 'lib/fluent/plugin/in_groonga.rb', line 193 def on_connect @parser = HTTP::Parser.new(self) @repeater = @input.create_repeater(self) end |
#on_headers_complete(headers) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/fluent/plugin/in_groonga.rb', line 214 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_begin ⇒ Object
210 211 212 |
# File 'lib/fluent/plugin/in_groonga.rb', line 210 def @body = "" end |
#on_message_complete ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/fluent/plugin/in_groonga.rb', line 237 def 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 @input.emit(command, params) end end |
#on_read(data) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/fluent/plugin/in_groonga.rb', line 198 def on_read(data) begin @parser << data rescue HTTP::Parser::Error $log.error("[input][groonga][error] " + "failed to parse HTTP request:", :error => $!.to_s) $log.error_backtrace close end end |