Skip to content

Instantly share code, notes, and snippets.

@erikbuild
Last active December 11, 2015 09:59
Show Gist options
  • Save erikbuild/4583889 to your computer and use it in GitHub Desktop.
Save erikbuild/4583889 to your computer and use it in GitHub Desktop.
require 'net/http'
def get_response(url)
uri = URI.parse(url)
path = (uri.path.empty?) ? '/' : uri.path
request = Net::HTTP.new(uri.hostname, uri.port)
request.request_head(path)
end
def is_site_up?(url)
response = get_response(urL)
["200", "302"].include? response.code
end
p is_site_up? "http://stackoverflow.com"
#=> false
p is_site_up? "http://www.business.uconn.edu"
#=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment