Created
March 24, 2021 11:29
-
-
Save stereosupersonic/28346d9618bd78785c69accd60a41428 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remote_file_exits?(url, limit=10) | |
raise ArgumentError, 'too many HTTP redirects' if limit == 0 | |
uri = URI(url) | |
response = Net::HTTP.get_response(uri) | |
case response | |
when Net::HTTPNotFound then | |
false | |
when Net::HTTPSuccess then | |
true | |
when Net::HTTPRedirection then | |
location = response['location'] | |
warn "redirected to #{location}" | |
file_exists?(location, limit - 1) | |
else | |
raise response.value | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment