Sha256: 6e1b49937051ee49a39e98573c1c6b5b88ce5a5648da64cfaca6c7be2f57d25d

Contents?: true

Size: 902 Bytes

Versions: 20

Compression:

Stored size: 902 Bytes

Contents

module CypressRails
  class Server
    class Checker
      TRY_HTTPS_ERRORS = [EOFError, Net::ReadTimeout, Errno::ECONNRESET].freeze

      def initialize(host, port)
        @host, @port = host, port
        @ssl = false
      end

      def request(&block)
        ssl? ? https_request(&block) : http_request(&block)
      rescue *TRY_HTTPS_ERRORS
        res = https_request(&block)
        @ssl = true
        res
      end

      def ssl?
        @ssl
      end

      private

      def http_request(&block)
        make_request(read_timeout: 2, &block)
      end

      def https_request(&block)
        make_request(**ssl_options, &block)
      end

      def make_request(**options, &block)
        Net::HTTP.start(@host, @port, options.merge(max_retries: 0), &block)
      end

      def ssl_options
        {use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE}
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
cypress-rails-0.8.0.rc1 lib/cypress-rails/server/checker.rb
cypress-rails-0.7.1 lib/cypress-rails/server/checker.rb
cypress-rails-0.7.0 lib/cypress-rails/server/checker.rb
cypress-rails-0.6.1 lib/cypress-rails/server/checker.rb
cypress-rails-0.6.0 lib/cypress-rails/server/checker.rb
cypress-rails-0.5.5 lib/cypress-rails/server/checker.rb
cypress-rails-0.5.4 lib/cypress-rails/server/checker.rb
cypress-rails-0.5.3 lib/cypress-rails/server/checker.rb
cypress-rails-0.5.2 lib/cypress-rails/server/checker.rb
cypress-rails-0.5.1 lib/cypress-rails/server/checker.rb
cypress-rails-0.5.0 lib/cypress-rails/server/checker.rb
cypress-rails-0.4.2 lib/cypress-rails/server/checker.rb
cypress-rails-0.4.1 lib/cypress-rails/server/checker.rb
cypress-rails-0.4.0 lib/cypress-rails/server/checker.rb
cypress-rails-0.3.0 lib/cypress-rails/server/checker.rb
cypress-rails-0.2.0 lib/cypress-rails/server/checker.rb
cypress-rails-0.1.5 lib/cypress-rails/server/checker.rb
cypress-rails-0.1.4 lib/cypress-rails/server/checker.rb
cypress-rails-0.1.3 lib/cypress-rails/server/checker.rb
cypress-rails-0.1.2 lib/cypress-rails/server/checker.rb