lib/fluent/plugin/in_http.rb in fluentd-1.12.0.rc1 vs lib/fluent/plugin/in_http.rb in fluentd-1.12.0.rc2
- old
+ new
@@ -78,10 +78,12 @@
config_param :respond_with_empty_img, :bool, default: false
desc 'Respond status code with 204.'
config_param :use_204_response, :bool, default: false
desc 'Dump error log or not'
config_param :dump_error_log, :bool, default: true
+ desc 'Add QUERY_ prefix query params to record'
+ config_param :add_query_params, :bool, default: false
config_section :parse do
config_set_default :@type, 'in_http'
end
@@ -275,11 +277,11 @@
end
private
def on_server_connect(conn)
- handler = Handler.new(conn, @km, method(:on_request), @body_size_limit, @format_name, log, @cors_allow_origins)
+ handler = Handler.new(conn, @km, method(:on_request), @body_size_limit, @format_name, log, @cors_allow_origins, @add_query_params)
conn.on(:data) do |data|
handler.on_read(data)
end
@@ -324,10 +326,18 @@
record[k] = v
end
}
end
+ if @add_query_params
+ params.each_pair { |k, v|
+ if k.start_with?("QUERY_".freeze)
+ record[k] = v
+ end
+ }
+ end
+
if @add_remote_addr
record['REMOTE_ADDR'] = params['REMOTE_ADDR']
end
end
@@ -344,20 +354,21 @@
end
class Handler
attr_reader :content_type
- def initialize(io, km, callback, body_size_limit, format_name, log, cors_allow_origins)
+ def initialize(io, km, callback, body_size_limit, format_name, log, cors_allow_origins, add_query_params)
@io = io
@km = km
@callback = callback
@body_size_limit = body_size_limit
@next_close = false
@format_name = format_name
@log = log
@cors_allow_origins = cors_allow_origins
@idle = 0
+ @add_query_params = add_query_params
@km.add(self)
@remote_port, @remote_addr = io.remote_port, io.remote_addr
@parser = Http::Parser.new(self)
end
@@ -531,10 +542,20 @@
elsif @content_type =~ /^application\/msgpack/
params['msgpack'] = @body
end
path_info = uri.path
+ if (@add_query_params)
+
+ query_params = WEBrick::HTTPUtils.parse_query(uri.query)
+
+ query_params.each_pair {|k,v|
+ params["QUERY_#{k.gsub('-','_').upcase}"] = v
+ }
+ end
+
params.merge!(@env)
+
@env.clear
code, header, body = @callback.call(path_info, params)
body = body.to_s
header = header.dup if header.frozen?