Last active
June 17, 2016 17:26
-
-
Save subimage/25ea0358c65babdf87cbffdb21698a40 to your computer and use it in GitHub Desktop.
Check if an image can be hotlinked, or should be downloaded/not used.
This file contains hidden or 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
# Usage: | |
# CheckImageHotlinkStatus.call('http://some-domain/image.jpg') | |
class CheckImageHotlinkStatus | |
require 'net/http' | |
require 'uri' | |
def self.call(image_url) | |
uri = URI(image_url) | |
req = Net::HTTP::Get.new(uri) | |
req['Referer'] = 'http://your-site-here.com' | |
response = Net::HTTP.start(uri.hostname, uri.port) do |http| | |
http.request(req) | |
end | |
# Net::HTTPForbidden ...download & embed | |
# Net::HTTPOK ...fine to hotlink | |
# ...everything else probably remove / don't use it. (404, 500, etc.) | |
puts response.class | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment