diff options
author | Chris Gahan <chris@ill-logic.com> | 2006-02-02 05:41:11 +0000 |
---|---|---|
committer | Chris Gahan <chris@ill-logic.com> | 2006-02-02 05:41:11 +0000 |
commit | 470891dd372ccc20ecee092ea8389efbfd0b340f (patch) | |
tree | 15d52da696f02d0c24f6afbf6cd6714495258114 /data/rbot | |
parent | 48fc730b582aebc7f2a8a57e07e1d27914de1e55 (diff) |
Set a limit on the number of redirects...
Diffstat (limited to 'data/rbot')
-rw-r--r-- | data/rbot/plugins/url.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/data/rbot/plugins/url.rb b/data/rbot/plugins/url.rb index 2b5b468e..3fa9f62d 100644 --- a/data/rbot/plugins/url.rb +++ b/data/rbot/plugins/url.rb @@ -30,9 +30,13 @@ class UrlPlugin < Plugin "[Link Info] title: #{title}" end - def get_title_for_url(uri_str) + def get_title_for_url(uri_str, depth=10) # This god-awful mess is what the ruby http library has reduced me to. # Python's HTTP lib is so much nicer. :~( +
+ if depth == 0
+ raise "Error: Maximum redirects hit."
+ end
puts "+ Getting #{uri_str}" url = URI.parse(uri_str) @@ -50,7 +54,7 @@ class UrlPlugin < Plugin puts "+ redirect location: #{redirect_to}" url = URI.join url.to_s, redirect_to puts "+ whee, redirecting to #{url.to_s}!" - title = get_title_for_url(url.to_s) + title = get_title_for_url(url.to_s, depth-1) when Net::HTTPSuccess then if head['content-type'] =~ /^text\// and (not head['content-length'] or head['content-length'].to_i < 400000) # since the content is 'text/*' and is small enough to |