Skip to content

Instantly share code, notes, and snippets.

@SebAshton
Last active August 29, 2015 14:03
Show Gist options
  • Save SebAshton/3f50a4922035c659e168 to your computer and use it in GitHub Desktop.
Save SebAshton/3f50a4922035c659e168 to your computer and use it in GitHub Desktop.
def remote_file_exists?(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
end
response = http.head(uri.request_uri)
case response
when Net::HTTPSuccess then return true
when Net::HTTPRedirection then return false
end
rescue => e
return false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment