lib/url_canonicalize/request.rb in url_canonicalize-0.1.14 vs lib/url_canonicalize/request.rb in url_canonicalize-0.1.15

- old
+ new

@@ -13,10 +13,11 @@ def with_uri(uri) @uri = uri @url = nil @host = nil + @request = nil @response = nil @location = nil @html = nil self @@ -58,23 +59,20 @@ rescue *NETWORK_EXCEPTIONS => e handle_failure(e.class, e.message) end def handle_success - @canonical_url = $LAST_MATCH_INFO['url'] if /<(?<url>.+)>\s*;\s*rel="canonical"/i =~ (response['link'] || '') + @canonical_url = $LAST_MATCH_INFO['url'] if (response['link'] || '') =~ /<(?<url>.+)>\s*;\s*rel="canonical"/i - if http_method == :head - self.http_method = :get - fetch - else - enhanced_response - end + return enhanced_response if canonical_url || http_method == :get + + self.http_method = :get + fetch end def handle_redirection case response when Net::HTTPFound, Net::HTTPMovedTemporarily, Net::HTTPTemporaryRedirect # Temporary redirection - self.http_method = :get handle_success else # Permanent redirection if location URLCanonicalize::Response::Redirect.new(location) else