<commit_before>require 'vcr/util/version_checker'
require 'vcr/request_handler'
require 'typhoeus'

if Float(Typhoeus::VERSION[/^\d+\.\d+/]) < 0.5
  require 'vcr/library_hooks/typhoeus_0.4'
else
  VCR::VersionChecker.new('Typhoeus', Typhoeus::VERSION, '0.5.0', '0.5').check_version!

  module VCR
    class LibraryHooks
      # @private
      module Typhoeus
        # @private
        class RequestHandler < ::VCR::RequestHandler
          attr_reader :request
          def initialize(request)
            @request = request
            request.block_connection = false if VCR.turned_on?
          end

          def vcr_request
            @vcr_request ||= VCR::Request.new \
              request.options.fetch(:method, :get),
              request.url,
              request.options.fetch(:body, ""),
              request.options.fetch(:headers, {})
          end

        private

          def externally_stubbed?
            ::Typhoeus::Expectation.find_by(request)
          end

          def set_typed_request_for_after_hook(*args)
            super
            request.instance_variable_set(:@__typed_vcr_request, @after_hook_typed_request)
          end

          def on_unhandled_request
            invoke_after_request_hook(nil)
            super
          end

          def on_stubbed_by_vcr_request
            ::Typhoeus::Response.new \
              :http_version   => stubbed_response.http_version,
              :code           => stubbed_response.status.code,
              :status_message => stubbed_response.status.message,
              :headers        => stubbed_response_headers,
              :body           => stubbed_response.body,
              :mock           => true
          end

          def stubbed_response_headers
            @stubbed_response_headers ||= {}.tap do |hash|
              stubbed_response.headers.each do |key, values|
                hash[key] = values.size == 1 ? values.first : values
              end if stubbed_response.headers
            end
          end
        end

        # @private
        def self.vcr_response_from(response)
          VCR::Response.new \
            VCR::ResponseStatus.new(response.code, response.status_message),<commit_msg>Add effective_url to stubbed Typheous response<commit_after>require 'vcr/util/version_checker'
require 'vcr/request_handler'
require 'typhoeus'

if Float(Typhoeus::VERSION[/^\d+\.\d+/]) < 0.5
  require 'vcr/library_hooks/typhoeus_0.4'
else
  VCR::VersionChecker.new('Typhoeus', Typhoeus::VERSION, '0.5.0', '0.5').check_version!

  module VCR
    class LibraryHooks
      # @private
      module Typhoeus
        # @private
        class RequestHandler < ::VCR::RequestHandler
          attr_reader :request
          def initialize(request)
            @request = request
            request.block_connection = false if VCR.turned_on?
          end

          def vcr_request
            @vcr_request ||= VCR::Request.new \
              request.options.fetch(:method, :get),
              request.url,
              request.options.fetch(:body, ""),
              request.options.fetch(:headers, {})
          end

        private

          def externally_stubbed?
            ::Typhoeus::Expectation.find_by(request)
          end

          def set_typed_request_for_after_hook(*args)
            super
            request.instance_variable_set(:@__typed_vcr_request, @after_hook_typed_request)
          end

          def on_unhandled_request
            invoke_after_request_hook(nil)
            super
          end

          def on_stubbed_by_vcr_request
            ::Typhoeus::Response.new \
              :http_version   => stubbed_response.http_version,
              :code           => stubbed_response.status.code,
              :status_message => stubbed_response.status.message,
              :headers        => stubbed_response_headers,
              :body           => stubbed_response.body,
              :effective_url  => request.url,
              :mock           => true
          end

          def stubbed_response_headers
            @stubbed_response_headers ||= {}.tap do |hash|
              stubbed_response.headers.each do |key, values|
                hash[key] = values.size == 1 ? values.first : values
              end if stubbed_response.headers
            end
          end
        end

        # @private
        def self.vcr_response_from(response)
          VCR::Response.new \
            VCR::ResponseStatus.new(response.code, response.status_message),
{'fraction_non_alphanumeric': 0.09187513836617224, 'fraction_numerical': 0.004427717511622758, 'mean_word_length': 1.8219862585883824, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, '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': '5981003', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1276, 'n_words': 220}