]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/url.rb
Fixed a bug that cut off the query-part of the url, cleaned up the redirect url joining.
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / url.rb
index b7e10b3d57965b442dca52a6f02c3fc802b0651a..a4e963590c493f17cb34f3de80ee7422f889ba77 100644 (file)
@@ -1,7 +1,7 @@
 require 'net/http'
 require 'uri'
 require 'cgi'
-
+\r
 Url = Struct.new("Url", :channel, :nick, :time, :url)
 TITLE_RE = /<\s*?title\s*?>(.+?)<\s*?\/title\s*?>/im
 
@@ -48,21 +48,15 @@ class UrlPlugin < Plugin
           # call self recursively if this is a redirect
           redirect_to = head['location']
           puts "+ redirect location: #{redirect_to}"
-          absolute_uris = URI.extract redirect_to
-          raise "wtf! redirect = #{redirect_to}" if absolute_uris.size > 1
-          if absolute_uris.size == 1
-            url = URI.parse absolute_uris[0]
-          else
-            url.path = redirect_to
-          end
-          puts "+ whee, redirect to #{url.to_s}!"
+          url = URI.join url.to_s, redirect_to
+          puts "+ whee, redirecting to #{url.to_s}!"
           title = get_title_for_url(url.to_s)
         when Net::HTTPSuccess then
           if head['content-type'] =~ /^text\//
             # content is 'text/*'
             # retrieve the title from the page
             puts "+ getting #{url.path}"
-            response = http.request_get(url.path)
+            response = http.request_get(url.request_uri)
             return get_title_from_html(response.body)
           else
             # content isn't 'text/*'... display info about the file.