18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/web_checker/http.rb', line 18
def accessible?
return false if @limit == 0
begin
Net::HTTP.start(@uri.host, @uri.port, :use_ssl => @uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
request = Net::HTTP::Get.new(@uri.request_uri)
response = http.request(request)
case response
when Net::HTTPSuccess then true
when Net::HTTPClientError then false
when Net::HTTPServerError then false
when Net::HTTPRedirection
location = response['location']
unless location.include?('://')
host_with_protocol = @uri_str[/^[^\:]+\:\/\/[^\/]+/, 0]
location = host_with_protocol + location
end
self.class.new(location, @limit - 1).accessible?
else
false
end
end
rescue SocketError
false
end
end
|