From: Alex Young Date: 2006-08-17T17:20:57+09:00 Subject: Re: Test For JPEG Image Over HTTP Neil Charlton wrote: > Hi > > I would like to test for the existence of a .jpg image on a remote > server over HTTP. > > I have tried 2 different methods but they are not what I need. > > Method 1: > > require 'open-uri' > if open('http://example.net/path/to/image.jpg') > > end > require 'net/http' # Strict existence def url_exists?(path) u = URI.parse(path) h = Net::HTTP.new(u.host, u.port) r = h.head(u.path) return Net::HTTPOK === r end # Lack of non-existence def url_found?(path) u = URI.parse(path) h = Net::HTTP.new(u.host, u.port) r = h.head(u.path) return !(Net::HTTPNotFound === r) end -- Alex