<commit_before>module Rack
  # Router
  #
  # Show WebProfiler page if the request path match with one
  # of the webprofiler routes.
  class WebProfiler::Router
    BASE_PATH = "/_rwpt".freeze

    class << self
      # Get response for given request.
      #
      # @param request [Rack::WebProfiler::Request]
      #
      # @return [Rack::Reponse, false]
      def response_for(request)
        @request = request
        path     = Rack::Utils.unescape(request.path_info)

        # Stop process if the request path does not start
        # by the BASE_PATH
        return false unless path.start_with?(BASE_PATH)

        path.slice!(BASE_PATH)

        route(request, path)
      end

      # Route!
      def route(request, path)
        controller = WebProfiler::Controller.new(request)

        if request.get? && path =~ %r{^\/toolbar\/([a-z0-9]*)(\/)?$}
          controller.show_toolbar(Regexp.last_match(1))
        elsif request.get? && path =~ %r{^\/clean(\/)?$}
          controller.delete
        elsif request.get? && path =~ %r{^(\/)?$}
          controller.index
        elsif request.get? && path =~ %r{^\/([a-z0-9]*)(\/)?$}
          controller.show(Regexp.last_match(1))
        else
          false
        end
      end

      # Get url for toobar.
      #
      # @param token [String]
      #
      # @return [String]
      def url_for_toolbar(token)
        "#{@request.script_name}#{BASE_PATH}/toolbar/#{token}"
      end

      # Get url for the webprofiler.
      #
      # @param token [String, nil]
      #
      # @return [String]
      def url_for_profiler(token = nil)
        "#{@request.script_name}#{BASE_PATH}/#{token}"
      end<commit_msg>Update Router to serve profiler assets<commit_after>module Rack
  # Router
  #
  # Show WebProfiler page if the request path match with one
  # of the webprofiler routes.
  class WebProfiler::Router
    BASE_PATH = "/_rwpt".freeze

    class << self
      # Get response for given request.
      #
      # @param request [Rack::WebProfiler::Request]
      #
      # @return [Rack::Reponse, false]
      def response_for(request)
        @request = request
        path     = Rack::Utils.unescape(request.path_info)

        # Stop process if the request path does not start
        # by the BASE_PATH
        return false unless path.start_with?(BASE_PATH)

        path.slice!(BASE_PATH)

        route(request, path)
      end

      # Route!
      def route(request, path)
        controller = WebProfiler::Controller.new(request)

        if request.get? && path =~ %r{^\/assets\/(.*)(\/)?$}
          serve_asset(Regexp.last_match(1))
        elsif request.get? && path =~ %r{^\/toolbar\/([a-z0-9]*)(\/)?$}
          controller.show_toolbar(Regexp.last_match(1))
        elsif request.get? && path =~ %r{^\/clean(\/)?$}
          controller.delete
        elsif request.get? && path =~ %r{^(\/)?$}
          controller.index
        elsif request.get? && path =~ %r{^\/([a-z0-9]*)(\/)?$}
          controller.show(Regexp.last_match(1))
        else
          false
        end
      end

      # Serve assets.
      def serve_asset(path)
        rf = Rack::File.new(::File.expand_path("../../templates/assets/", __FILE__))
        request = @request.dup
        request.env[PATH_INFO] = path

        path_info = Utils.unescape(request.env[PATH_INFO])
        clean_path_info = Utils.clean_path_info(path_info)

        status, headers, body = rf.call(request.env)
        Rack::Response.new(body, status, headers)
      end

      # Get url for asset.
      #
      # @param path [String]
      #
      # @return [String]
      def url_for_asset(path)
        "#{@request.script_name}#{BASE_PATH}/assets/#{path}"
      end

      # Get url for toobar.
      #
      # @param token [String]
      #
      # @return [String]
      def url_for_toolbar(token)
        "#{@request.script_name}#{BASE_PATH}/toolbar/#{token}"
      end

      # Get url for the webprofiler.
      #
      # @param token [String, nil]
      #
      # @return [String]
      def url_for_profiler(token = nil)
        "#{@request.script_name}#{BASE_PATH}/#{token}"
      end
{'fraction_non_alphanumeric': 0.13926499032882012, 'fraction_numerical': 0.0031431334622823983, 'mean_word_length': 2.0804169769173493, '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': '6864383', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1346, 'n_words': 283}