<commit_before>require "jerk/version"

require 'jerk/railtie' if defined?(Rails)

module Jerk
  module Base
    def initialize(app)
      @app = app
    end

    def call(env)
      @app.call(env)
    end

    def each(&block); end

    def url_without_query_string(env)
      req = Rack::Request.new(env)
      req.base_url + req.script_name + req.path_info
    end

    def downcased_url(env)
      if env['QUERY_STRING'].empty?
        url_without_query_string(env).downcase
      else
        url_without_query_string(env).downcase + "?#{env['QUERY_STRING']}"
      end
    end
  end

  ### DEFAULT
  # Jerk::Redirect — issue a 301 redirect to the downcased version
  class Redirect
    include Base

    def call(env)
      if url_without_query_string(env)[/[A-Z]/]
        [301, { Location: downcased_url(env) }, self]
      else
        super
      end
    end
  end

  # Jerk::Ignore — Just downcase the URL for Rails without redirecting the user
  class Ignore
    include Base

    def call(env)
      env['HOST'].to_s.downcase!
      env['SCRIPT_NAME'].to_s.downcase!
      env['PATH_INFO'].to_s.downcase!
      super
    end
  end
end

<commit_msg>Fix Rack::Lint errors<commit_after>require "jerk/version"

require 'jerk/railtie' if defined?(Rails)

module Jerk
  module Base
    def initialize(app)
      @app = app
    end

    def call(env)
      @app.call(env)
    end

    def each(&block); end

    def url_without_query_string(env)
      req = Rack::Request.new(env)
      req.base_url + req.script_name + req.path_info
    end

    def downcased_url(env)
      if env['QUERY_STRING'].empty?
        url_without_query_string(env).downcase
      else
        url_without_query_string(env).downcase + "?#{env['QUERY_STRING']}"
      end
    end
  end

  ### DEFAULT
  # Jerk::Redirect — issue a 301 redirect to the downcased version
  class Redirect
    include Base

    def call(env)
      if url_without_query_string(env)[/[A-Z]/]
        [301, { 'Location' => downcased_url(env), 'Content-Type' => 'text/plain' }, self]
      else
        super
      end
    end
  end

  # Jerk::Ignore — Just downcase the URL for Rails without redirecting the user
  class Ignore
    include Base

    def call(env)
      env['HOST'].to_s.downcase!
      env['SCRIPT_NAME'].to_s.downcase!
      env['PATH_INFO'].to_s.downcase!
      super
    end
  end
end


{'fraction_non_alphanumeric': 0.10575296108291032, 'fraction_numerical': 0.005076142131979695, 'mean_word_length': 2.556390977443609, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7604564', 'n_tokens_mistral': 838, 'n_tokens_neox': 808, 'n_words': 192}