<commit_before># frozen_string_literal: true

module Capybara
  class Server
    class Checker
      def initialize(host, port)
        @host, @port = host, port
        @ssl = false
      end

      def request(&block)
        ssl? ? https_request(&block) : http_request(&block)
      rescue EOFError, Net::ReadTimeout
        res = https_request(&block)
        @ssl = true
        res
      end

      def ssl?
        @ssl
      end

    private

      def http_request(&block)
        Net::HTTP.start(@host, @port, read_timeout: 2, &block)
      end

      def https_request(&block)
        Net::HTTP.start(@host, @port, ssl_options, &block)
      end

      def ssl_options
        { use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE }
      end
    end
  end
end<commit_msg>Add Errno::ECONNRESET to the errors that trigger https attempt<commit_after># frozen_string_literal: true

module Capybara
  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)
        Net::HTTP.start(@host, @port, read_timeout: 2, &block)
      end

      def https_request(&block)
        Net::HTTP.start(@host, @port, ssl_options, &block)
      end

      def ssl_options
        { use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE }
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09580130100532229, 'fraction_numerical': 0.0011827321111768185, 'mean_word_length': 2.210626185958254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6319860', 'n_tokens_mistral': 546, 'n_tokens_neox': 531, 'n_words': 136}