<commit_before>require 'openssl'
require 'uri'
require 'faraday'

module Percy
  class Client
    module Connection
      class NoCookiesHTTPClientAdapter < Faraday::Adapter::HTTPClient
        def client
          @client ||= ::HTTPClient.new
          @client.cookie_manager = nil
          # Turn off SSLv2 and SSLv3 to force TLS because CloudFlare smartly blocks SSLv2 and SSLv3.
          @client.ssl_config.options |= OpenSSL::SSL::OP_NO_SSLv2
          @client.ssl_config.options |= OpenSSL::SSL::OP_NO_SSLv3
          @client
        end
      end

      class NiceErrorMiddleware < Faraday::Response::Middleware
        CLIENT_ERROR_STATUS_RANGE = 400...600

        def on_complete(env)
          case env[:status]
          when 407
            # Mimic the behavior that we get with proxy requests with HTTPS.
            raise Faraday::Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
          when CLIENT_ERROR_STATUS_RANGE
            raise Percy::Client::ClientError.new(
              env, "Got #{env.status} (#{env.method.upcase} #{env.url}):\n#{env.body}")
          end
        end
      end
<commit_msg>Force use of TLSv1 connections to Percy API.<commit_after>require 'openssl'
require 'uri'
require 'faraday'

module Percy
  class Client
    module Connection
      class NoCookiesHTTPClientAdapter < Faraday::Adapter::HTTPClient
        def client
          @client ||= ::HTTPClient.new
          @client.cookie_manager = nil
          # Turn off SSLv2 and SSLv3 to force TLS because CloudFlare smartly blocks SSLv2 and SSLv3.
          @client.ssl_config.options |= OpenSSL::SSL::OP_NO_SSLv2
          @client.ssl_config.options |= OpenSSL::SSL::OP_NO_SSLv3
          @client.ssl_config.ssl_version = :TLSv1
          @client
        end
      end

      class NiceErrorMiddleware < Faraday::Response::Middleware
        CLIENT_ERROR_STATUS_RANGE = 400...600

        def on_complete(env)
          case env[:status]
          when 407
            # Mimic the behavior that we get with proxy requests with HTTPS.
            raise Faraday::Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
          when CLIENT_ERROR_STATUS_RANGE
            raise Percy::Client::ClientError.new(
              env, "Got #{env.status} (#{env.method.upcase} #{env.url}):\n#{env.body}")
          end
        end
      end

{'fraction_non_alphanumeric': 0.08894536213468869, 'fraction_numerical': 0.01609487505294367, 'mean_word_length': 2.413294797687861, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4601359', 'n_tokens_mistral': 707, 'n_tokens_neox': 671, 'n_words': 175}