module SAAL
Constants
- CHARTSCONF
- CONFDIR
- DBCONF
- SENSORSCONF
- VERSION
Public Class Methods
do_http_get(host, port, path, user, pass, timeout)
click to toggle source
# File lib/http.rb 5 def SAAL::do_http_get(host, port, path, user, pass, timeout) 6 begin 7 http = Net::HTTP.new(host,port) 8 # Timeout faster when the other side doesn't respond 9 http.open_timeout = timeout 10 http.read_timeout = timeout 11 req = Net::HTTP::Get.new(path) 12 req.basic_auth(user, pass) if user && pass 13 response = http.request(req) 14 if response.code != "200" 15 #$stderr.puts "ERROR: Code #{response.code}" 16 #$stderr.puts response.body 17 return nil 18 end 19 return response 20 rescue Exception 21 return nil 22 end 23 end
do_http_get_digest(host, port, path, user, pass, timeout)
click to toggle source
# File lib/http.rb 25 def SAAL::do_http_get_digest(host, port, path, user, pass, timeout) 26 begin 27 uri = URI.parse "http://#{host}:#{port}/#{path}" 28 digest_auth = Net::HTTP::DigestAuth.new 29 uri.user = user 30 uri.password = pass 31 http = Net::HTTP.new(host,port) 32 # Timeout faster when the other side doesn't respond 33 http.open_timeout = timeout 34 http.read_timeout = timeout 35 req = Net::HTTP::Get.new(path) 36 response = http.request(req) 37 if response.code == "401" && user && pass 38 auth = digest_auth.auth_header uri, response['www-authenticate'], 'GET' 39 req.add_field 'Authorization', auth 40 response = http.request(req) 41 end 42 if response.code != "200" 43 #$stderr.puts "ERROR: Code #{response.code}" 44 #$stderr.puts response.body 45 return nil 46 end 47 return response 48 rescue Exception 49 return nil 50 end 51 end