Skip to content

Instantly share code, notes, and snippets.

@infernalsirius
Forked from tb/working_url.rb
Created May 26, 2017 03:37
Show Gist options
  • Save infernalsirius/3b39c905f0f19b1191861267a0a87b06 to your computer and use it in GitHub Desktop.
Save infernalsirius/3b39c905f0f19b1191861267a0a87b06 to your computer and use it in GitHub Desktop.
Check if URL exists in Ruby
require 'net/http'
def working_url?(url_str)
url = URI.parse(url_str)
Net::HTTP.start(url.host, url.port) do |http|
http.head(url.request_uri).code == '200'
end
rescue
false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment