Sha256: 603a45452b5b38ca4e14a2e80991e5073c0fab7a01608b171b4a084811aadaa0
Contents?: true
Size: 960 Bytes
Versions: 1
Compression:
Stored size: 960 Bytes
Contents
require 'net/http' module ShuntCache module Checker class << self def wait_for_http(url, options = {}) retries = options.fetch(:retry, 10) wait_time = options.fetch(:wait_time, 6) uri = URI(url) retries.times do begin response = request(uri, options) code = response.code.to_i return true if 200 <= code && 399 >= code rescue Errno::ECONNREFUSED, Timeout::Error => e end sleep(wait_time) end false end def request(uri, options = {}) timeout = options.fetch(:timeout, 10) response = nil Net::HTTP.start(uri.host, uri.port) do |http| http.read_timeout = timeout request = Net::HTTP::Get.new(uri.path) request['Host'] = options[:host] if options[:host] response = http.request(request) end response end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shunt_cache-0.1.0 | lib/shunt_cache/checker.rb |