summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-07-23 22:53:37 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-07-23 22:53:37 +0000
commitc1895f58ebb1607bf1bfc5477112a59b47252b98 (patch)
tree67d31c9b1035c0f3e8170a2641955f6bf777b7f2
parent19ce0218931fbf4d5c9e76d26655ff8c93d073a9 (diff)
Fix yielding in {{{httputil.get}}} and {{{httputil.head}}} and usage of [] instead of () in remove_stale_cache
-rw-r--r--lib/rbot/httputil.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/rbot/httputil.rb b/lib/rbot/httputil.rb
index 7edc286d..19e2a31a 100644
--- a/lib/rbot/httputil.rb
+++ b/lib/rbot/httputil.rb
@@ -132,7 +132,7 @@ class HttpUtil
#
# simple get request, returns (if possible) response body following redirs
# and caching if requested
- # it yields the urls it gets redirected to, for future uses
+ # if a block is given, it yields the urls it gets redirected to
def get(uri, readtimeout=10, opentimeout=5, max_redir=@bot.config["http.max_redir"], cache=false)
proxy = get_proxy(uri)
proxy.open_timeout = opentimeout
@@ -140,6 +140,7 @@ class HttpUtil
begin
proxy.start() {|http|
+ yield uri.request_uri() if block_given?
resp = http.get(uri.request_uri(), @headers)
case resp
when Net::HTTPSuccess
@@ -161,7 +162,7 @@ class HttpUtil
return resp.body
when Net::HTTPRedirection
debug "Redirecting #{uri} to #{resp['location']}"
- yield resp['location']
+ yield resp['location'] if block_given?
if max_redir > 0
return get( URI.parse(resp['location']), readtimeout, opentimeout, max_redir-1, cache)
else
@@ -187,13 +188,14 @@ class HttpUtil
begin
proxy.start() {|http|
+ yield uri.request_uri() if block_given?
resp = http.head(uri.request_uri(), @headers)
case resp
when Net::HTTPSuccess
return resp
when Net::HTTPRedirection
debug "Redirecting #{uri} to #{resp['location']}"
- yield resp['location']
+ yield resp['location'] if block_given?
if max_redir > 0
return head( URI.parse(resp['location']), readtimeout, opentimeout, max_redir-1)
else
@@ -279,7 +281,7 @@ class HttpUtil
def remove_stale_cache
now = Time.new
@cache.reject! { |k, val|
- !val.key?[:last_modified] && expired?(val, now)
+ !val.key?(:last_modified) && expired?(val, now)
}
end