lib/fluent/plugin/out_bugsnag.rb in fluent-plugin-bugsnag-0.1.0 vs lib/fluent/plugin/out_bugsnag.rb in fluent-plugin-bugsnag-0.2.0
- old
+ new
@@ -15,17 +15,18 @@
[tag, time, record].to_msgpack
end
def write(chunk)
chunk.msgpack_each do |(tag,time,record)|
- request(record['url'], record['body'])
+ options = record['options'] || {}
+ request(record['url'], record['body'], options)
end
end
private
- def request(url, body)
+ def request(url, body, options = {})
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port, @bugsnag_proxy_host, @bugsnag_proxy_port, @bugsnag_proxy_user, @bugsnag_proxy_password)
http.read_timeout = @bugsnag_timeout
http.open_timeout = @bugsnag_timeout
@@ -34,15 +35,24 @@
# the default in 1.9+, but required for 1.8
# http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
- request = Net::HTTP::Post.new(path(uri), {"Content-Type" => "application/json"})
+ headers = options.key?('headers') ? options['headers'] : {}
+ headers.merge!(default_headers)
+
+ request = Net::HTTP::Post.new(path(uri), headers)
request.body = body
http.request(request)
end
def path(uri)
uri.path == "" ? "/" : uri.path
+ end
+
+ def default_headers
+ {
+ "Content-Type" => "application/json",
+ }
end
end
end