lib/url_canonicalize/request.rb in url_canonicalize-0.2.0 vs lib/url_canonicalize/request.rb in url_canonicalize-0.2.1
- old
+ new
@@ -36,11 +36,11 @@
def response
@response ||= do_http_request
end
# We can stub this method in testing then call #response any number of times
- def do_http_request #:nodoc: internal use only
+ def do_http_request # :nodoc: internal use only
http.do_request request # Some URLs can throw an exception here
end
def request
@request ||= request_for_method
@@ -168,10 +168,11 @@
@http_method = :get if /(linkedin|crunchbase).com/ =~ host
end
def relative_to_absolute(partial_url)
return unless partial_url
+
partial_uri = ::URI.parse(partial_url)
if partial_uri.host
partial_url # It's already absolute
else
@@ -181,12 +182,14 @@
nil
end
def log_response
return unless ENV['DEBUG']
+
puts "#{http_method.upcase} #{url} #{response.code} #{response.message}"
return unless ENV['DEBUG'].casecmp('headers')
+
response.each { |k, v| puts " #{k}:\t#{v}" }
end
NETWORK_EXCEPTIONS = [
EOFError,