Published in: Ruby
require 'net/http' module Url IMAGE_MIME_TYPES = ['image/jpeg', 'image/jpg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png'] def self.image?(url) url = URI.parse(url) Net::HTTP.start(url.host, url.port) do |http| res = http.head(url.path) IMAGE_MIME_TYPES.include?(res.content_type) if Net::HTTPSuccess end end end
You need to login to post a comment.
