<commit_before>module Excon
  module Middleware
    class RedirectFollower < Excon::Middleware::Base
      def response_call(datum)
        if datum.has_key?(:response) && [:get, :head].include?(datum[:method].to_s.downcase.to_sym)
          case datum[:response][:status]
          when 301, 302, 303, 307
            uri_parser = datum[:uri_parser] || Excon.defaults[:uri_parser]
            _, location = datum[:response][:headers].detect do |key, value|
              key.casecmp('Location') == 0
            end
            uri = uri_parser.parse(location)

            port_string = if datum[:omit_default_port] && ((uri.scheme.casecmp('http') == 0 && uri.port.to_i == 80) || (uri.scheme.casecmp('https') == 0 && uri.port.to_i == 443))
              ''
            else
              ':' << uri.port.to_s
            end

            # delete old/redirect response
            datum.delete(:response)

            response = datum[:connection].request(
              datum.merge!(
                :headers    => (datum[:headers] || {}).merge({'Host' => '' << uri.host << port_string}),
                :host       => uri.host,
                :path       => uri.path,
                :port       => uri.port,
                :query      => uri.query,
                :scheme     => uri.scheme,
                :user       => (URI.decode(uri.user) if uri.user),
                :password   => (URI.decode(uri.password) if uri.password),
              )
            )
            datum.merge!({:response => response.data})
          else
            @stack.response_call(datum)
          end
        else<commit_msg>rearrange to avoid 1.8.7/ree syntax error<commit_after>module Excon
  module Middleware
    class RedirectFollower < Excon::Middleware::Base
      def response_call(datum)
        if datum.has_key?(:response) && [:get, :head].include?(datum[:method].to_s.downcase.to_sym)
          case datum[:response][:status]
          when 301, 302, 303, 307
            uri_parser = datum[:uri_parser] || Excon.defaults[:uri_parser]
            _, location = datum[:response][:headers].detect do |key, value|
              key.casecmp('Location') == 0
            end
            uri = uri_parser.parse(location)

            port_string = if datum[:omit_default_port] && ((uri.scheme.casecmp('http') == 0 && uri.port.to_i == 80) || (uri.scheme.casecmp('https') == 0 && uri.port.to_i == 443))
              ''
            else
              ':' << uri.port.to_s
            end

            # delete old/redirect response
            datum.delete(:response)

            response = datum[:connection].request(datum.merge!(
                :headers    => (datum[:headers] || {}).merge({'Host' => '' << uri.host << port_string}),
                :host       => uri.host,
                :path       => uri.path,
                :port       => uri.port,
                :query      => uri.query,
                :scheme     => uri.scheme,
                :user       => (URI.decode(uri.user) if uri.user),
                :password   => (URI.decode(uri.password) if uri.password),
            ))
            datum.merge!({:response => response.data})
          else
            @stack.response_call(datum)
          end
        else
{'fraction_non_alphanumeric': 0.144224830142063, 'fraction_numerical': 0.013279802347127856, 'mean_word_length': 1.6484055600981193, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, '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': '6529159', 'n_tokens_mistral': 980, 'n_tokens_neox': 914, 'n_words': 169}