]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/httputil.rb
fix the fix
[user/henk/code/ruby/rbot.git] / lib / rbot / httputil.rb
index b49a42b1293fd46d4badf2e1b7e9f2fca24aae22..e073a56d908109462c70edf7f416010ed4a9df09 100644 (file)
@@ -1,7 +1,9 @@
 module Irc
+module Utils
 
 require 'resolv'
 require 'net/http'
+require 'net/https'
 Net::HTTP.version_1_2
   
 # class for making http requests easier (mainly for plugins to use)
@@ -22,6 +24,7 @@ class HttpUtil
       :default => [],
       :desc => "List of regexps to check against a URI's hostname/ip to see if we should use the proxy to access this URI. All URIs are proxied by default if the proxy is set, so this is only required to re-include URIs that might have been excluded by the exclude list. e.g. exclude /.*\.foo\.com/, include bar\.foo\.com")
     BotConfig.register BotConfigArrayValue.new('http.proxy_exclude',
+      :default => [],
       :desc => "List of regexps to check against a URI's hostname/ip to see if we should use avoid the proxy to access this URI and access it directly")
 
   def initialize(bot)
@@ -43,7 +46,7 @@ class HttpUtil
 
     list = [uri.host]
     begin
-      list.push Resolv.getaddresses(uri.host)
+      list.concat Resolv.getaddresses(uri.host)
     rescue StandardError => err
       puts "warning: couldn't resolve host uri.host"
     end
@@ -89,10 +92,10 @@ class HttpUtil
 
     if @bot.config["http.use_proxy"]
       if (ENV['http_proxy'])
-        proxy = URI.parse ENV['http_proxy']
+        proxy = URI.parse ENV['http_proxy'] rescue nil
       end
       if (@bot.config["http.proxy_uri"])
-        proxy = URI.parse ENV['http_proxy_uri']
+        proxy = URI.parse @bot.config["http.proxy_uri"] rescue nil
       end
       if proxy
         debug "proxy is set to #{proxy.uri}"
@@ -105,7 +108,9 @@ class HttpUtil
       end
     end
     
-    return Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port, proxy_user, proxy_port)
+    h = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port, proxy_user, proxy_port)
+    h.use_ssl = true if uri.scheme == "https"
+    return h
   end
 
   # uri::         uri to query (Uri object)
@@ -135,5 +140,5 @@ class HttpUtil
     return nil
   end
 end
-
+end
 end