]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/httputil.rb
Better flood control
[user/henk/code/ruby/rbot.git] / lib / rbot / httputil.rb
index 6383d4e2ab9a7b8706083f370f36f0777c374f05..bcb05d885b8bd10b4bfc40296364ce4876d2ce9a 100644 (file)
@@ -45,7 +45,10 @@ class HttpUtil
     @headers = {
       'User-Agent' => "rbot http util #{$version} (http://linuxbrit.co.uk/rbot/)",
     }
+    @last_response = nil
   end
+  attr_reader :last_response
+  attr_reader :headers
 
   # if http_proxy_include or http_proxy_exclude are set, then examine the
   # uri to see if this is a proxied uri
@@ -178,12 +181,14 @@ class HttpUtil
         else
           debug "HttpUtil.get return code #{resp.code} #{resp.body}"
         end
+        @last_response = resp
         return nil
       }
     rescue StandardError, Timeout::Error => e
       error "HttpUtil.get exception: #{e.inspect}, while trying to get #{uri}"
       debug e.backtrace.join("\n")
     end
+    @last_response = nil
     return nil
   end
 
@@ -202,7 +207,7 @@ class HttpUtil
     begin
       proxy.start() {|http|
         yield uri.request_uri() if block_given?
-        resp = http.head(uri.request_uri(), @headers)
+        resp = http.request_head(uri.request_uri(), @headers)
         case resp
         when Net::HTTPSuccess
           return resp
@@ -217,12 +222,14 @@ class HttpUtil
         else
           debug "HttpUtil.head return code #{resp.code}"
         end
+        @last_response = resp
         return nil
       }
     rescue StandardError, Timeout::Error => e
       error "HttpUtil.head exception: #{e.inspect}, while trying to get #{uri}"
       debug e.backtrace.join("\n")
     end
+    @last_response = nil
     return nil
   end