class NetHTTPFetcher
Attributes
ca_path[RW]
Public Class Methods
new(read_timeout=20, open_timeout=20)
click to toggle source
# File lib/yadis/fetcher.rb, line 16 def initialize(read_timeout=20, open_timeout=20) @read_timeout = read_timeout @open_timeout = open_timeout @ca_path = nil end
Public Instance Methods
get(url, params = nil)
click to toggle source
# File lib/yadis/fetcher.rb, line 22 def get(url, params = nil) resp, final_url = do_get(url, params) if resp.nil? nil else [final_url, resp] end end
Protected Instance Methods
do_get(url, params, limit=5)
click to toggle source
do a GET following redirects limit deep
# File lib/yadis/fetcher.rb, line 58 def do_get(url, params, limit=5) if limit == 0 return nil end begin uri = URI.parse(url) http = get_http_obj(uri) resp = http.request_get(uri.request_uri, params) rescue nil else case resp when Net::HTTPSuccess return [resp, URI.parse(url).to_s] when Net::HTTPRedirection return do_get(resp["location"], params, limit-1) else return nil end end end
get_http_obj(uri)
click to toggle source
return a Net::HTTP object ready for use
# File lib/yadis/fetcher.rb, line 34 def get_http_obj(uri) http = Net::HTTP.new(uri.host, uri.port) http.read_timeout = @read_timeout http.open_timeout = @open_timeout if uri.scheme == 'https' if HAS_OPENSSL_ http.use_ssl = true if @ca_path http.ca_file = @ca_path http.verify_mode = OpenSSL::SSL::VERIFY_PEER else http.verify_mode = OpenSSL::SSL::VERIFY_NONE STDERR.puts("Warning: fetching over https without verifying server certificate") end else STDERR.puts('Warning: trying to fetch HTTPS URL without OpenSSL support') end end return http end