<commit_before>require 'zlib'
require 'rack/request'
require 'rack/response'
require 'rack/utils'
require 'time'

class SmartHttpController < ApplicationController
  unloadable

  # prevents login action to be filtered by check_if_login_required application scope filter
  skip_before_filter :check_if_login_required, :verify_authenticity_token

  before_filter :extract_parameters
  before_filter :find_repository
  before_filter :check_query
  before_filter :authenticate


  def index
    @request = Rack::Request.new(request.env)

    command, @requested_file, @rpc = match_routing(@request)

    return render_method_not_allowed if command == 'not_allowed'

    logger.info { "###### AUTHENTICATED ######" }
    logger.info { "command         : #{command}" }
    logger.info { "rpc             : #{@rpc}" }
    if !@user.nil?
      logger.info { "user_name       : #{@user.login}" }
      @authenticated = true
    else
      if @project.is_public
        logger.info { "user_name       : anonymous (project is public)" }
        @authenticated = true
      else
        @authenticated = false
      end
    end

    logger.info { "##########################" }

    self.method(command).call()
  end


  private


  def extract_parameters
    git_params = params[:git_params].split('/')
    @repo_path  = params[:repo_path]
    @is_push    = (git_params[0] == 'git-receive-pack' || params[:service] == 'git-receive-pack')
<commit_msg>Render not found if !command, strip HTTP prefix<commit_after>require 'zlib'
require 'rack/request'
require 'rack/response'
require 'rack/utils'
require 'time'

class SmartHttpController < ApplicationController
  unloadable

  # prevents login action to be filtered by check_if_login_required application scope filter
  skip_before_filter :check_if_login_required, :verify_authenticity_token

  before_filter :extract_parameters
  before_filter :find_repository
  before_filter :check_query
  before_filter :authenticate


  def index
    @request = Rack::Request.new(request.env)

    command, @requested_file, @rpc = match_routing(@request)

    return render_method_not_allowed if command == 'not_allowed'
    return render_not_found if !command

    logger.info { "###### AUTHENTICATED ######" }
    logger.info { "command         : #{command}" }
    logger.info { "rpc             : #{@rpc}" }
    if !@user.nil?
      logger.info { "user_name       : #{@user.login}" }
      @authenticated = true
    else
      if @project.is_public
        logger.info { "user_name       : anonymous (project is public)" }
        @authenticated = true
      else
        @authenticated = false
      end
    end

    logger.info { "##########################" }

    self.method(command).call()
  end


  private


  def extract_parameters
    git_params = params[:git_params].split('/')
    @repo_path = params[:repo_path].gsub(params[:prefix], '')
    @is_push   = (git_params[0] == 'git-receive-pack' || params[:service] == 'git-receive-pack')

{'fraction_non_alphanumeric': 0.12961719274680994, 'fraction_numerical': 0.000671591672263264, 'mean_word_length': 3.3808823529411764, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6946822', 'n_tokens_mistral': 918, 'n_tokens_neox': 873, 'n_words': 201}