Permalink
Browse files

Add Net::HTTP.url_exists?(url).

  • Loading branch information...
1 parent d599f11 commit 44d47a48830bf0b89a21ed03e1f426ab4648f0ef @alexisbernard committed Apr 7, 2013
Showing with 6 additions and 0 deletions.
  1. +6 −0 http.rb
View
@@ -31,5 +31,11 @@ def self.head_url(url)
options = {use_ssl: url.scheme.downcase == 'https'}
Net::HTTP.start(url.host, url.port, options) { |http| http.head(url.request_uri) }
end
+
+ def self.url_exists?(url)
+ Net::HTTP.head_url(url).is_a?(Net::HTTPOK)
+ rescue Net::HTTPServerError, Errno::ETIMEDOUT, Timeout::Error, SocketError
+ false
+ end
end
end

0 comments on commit 44d47a4

Please sign in to comment.