lib/riemann/babbler/plugins/helpers/rest.rb in riemann-babbler-2.8.4 vs lib/riemann/babbler/plugins/helpers/rest.rb in riemann-babbler-2.8.5
- old
+ new
@@ -1,9 +1,8 @@
#encoding: utf-8
-require 'uri'
-require 'net/http'
+require 'open-uri'
module Riemann
module Babbler
module Plugins
module Helpers
@@ -11,12 +10,16 @@
# http rest
def rest_get(url)
begin
Timeout::timeout(plugin.timeout) do
begin
- res = ::Net::HTTP.get_response(URI(url))
- raise ::Net::HTTPError unless res.kind_of?(::Net::HTTPSuccess)
- res.body
+ uri = URI(url)
+ if uri.userinfo
+ open("#{uri.scheme}://#{uri.hostname}:#{uri.port}#{uri.request_uri}",
+ :http_basic_authentication => [uri.user, uri.password]).read
+ else
+ open(url).read
+ end
rescue
raise "Get from url: #{url} failed"
end
end
rescue Timeout::Error