]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/httputil.rb
Adapt topic plugin to new IRC framework
[user/henk/code/ruby/rbot.git] / lib / rbot / httputil.rb
index 1a43c1850ec49e09e53f8e813ac149d7e23ebb80..6383d4e2ab9a7b8706083f370f36f0777c374f05 100644 (file)
@@ -133,8 +133,9 @@ class HttpUtil
   # simple get request, returns (if possible) response body following redirs
   # and caching if requested
   # if a block is given, it yields the urls it gets redirected to
+  # TODO we really need something to implement proper caching
   def get(uri_or_str, readtimeout=10, opentimeout=5, max_redir=@bot.config["http.max_redir"], cache=false)
-    if uri_or_str.class <= URI
+    if uri_or_str.kind_of?(URI)
       uri = uri_or_str
     else
       uri = URI.parse(uri_or_str.to_s)
@@ -150,7 +151,7 @@ class HttpUtil
         resp = http.get(uri.request_uri(), @headers)
         case resp
         when Net::HTTPSuccess
-          if cache
+          if cache && !(resp.key?('cache-control') && resp['cache-control']=='must-revalidate')
             k = uri.to_s
             @cache[k] = Hash.new
             @cache[k][:body] = resp.body
@@ -188,7 +189,7 @@ class HttpUtil
 
   # just like the above, but only gets the head
   def head(uri_or_str, readtimeout=10, opentimeout=5, max_redir=@bot.config["http.max_redir"])
-    if uri_or_str.class <= URI
+    if uri_or_str.kind_of?(URI)
       uri = uri_or_str
     else
       uri = URI.parse(uri_or_str.to_s)
@@ -230,7 +231,7 @@ class HttpUtil
   def get_cached(uri_or_str, readtimeout=10, opentimeout=5,
                  max_redir=@bot.config['http.max_redir'],
                  noexpire=@bot.config['http.no_expire_cache'])
-    if uri_or_str.class <= URI
+    if uri_or_str.kind_of?(URI)
       uri = uri_or_str
     else
       uri = URI.parse(uri_or_str.to_s)