<commit_before>module GenericApiRails
  class BaseController < ::ApplicationController
    before_filter :cors_set_access_control_headers
    before_filter :cors_preflight_check
    before_filter :api_setup

    skip_before_filter :verify_authenticity_token, :only => [:options]
    
    def options
    end

    # For all responses in this controller, return the CORS access control headers.
    def cors_set_access_control_headers
      response.headers['Access-Control-Allow-Origin'] = '*'
      response.headers['Access-Control-Allow-Credentials'] = 'true'
      response.headers['Access-Control-Allow-Methods'] = 'GET, PUT, POST, DELETE, OPTIONS, PATCH'
      response.headers['Access-Control-Max-Age'] = "1728000"
      response.headers['Access-Control-Allow-Headers'] = 'X-CSRF-Token, X-Requested-With, X-Prototype-Version, content-type, api-token, bzu-client-id'
    end

    # If this is a preflight OPTIONS request, then short-circuit the
    # request, return only the necessary headers and return an empty
    # text/plain.
    def cors_preflight_check
      if request.method == "OPTIONS"
        headers['Access-Control-Allow-Origin'] = '*'
        headers['Access-Control-Allow-Methods'] = 'GET, PUT, POST, DELETE, OPTIONS, PATCH'
        headers['Access-Control-Allow-Headers'] = 'X-CSRF-Token, X-Requested-With, X-Prototype-Version, content-type, api-token, bzu-client-id'
        headers['Access-Control-Max-Age'] = '1728000'
        render :text => '', :content_type => 'text/plain'
      end
    end

    def api_setup
      @params = params
      @request = request

      incoming_token = params[:api_token] || request.headers['api-token']

      api_token = ApiToken.find_by_token(incoming_token)
      logger.info "API TOKEN: #{api_token}"
      credential = api_token.credential if api_token
      token = api_token.token if api_token<commit_msg>Drop log and conditionally execute.<commit_after>module GenericApiRails
  class BaseController < ::ApplicationController
    before_filter :cors_set_access_control_headers
    before_filter :cors_preflight_check
    before_filter :api_setup

    skip_before_filter :verify_authenticity_token, :only => [:options]
    
    def options
    end

    # For all responses in this controller, return the CORS access control headers.
    def cors_set_access_control_headers
      response.headers['Access-Control-Allow-Origin'] = '*'
      response.headers['Access-Control-Allow-Credentials'] = 'true'
      response.headers['Access-Control-Allow-Methods'] = 'GET, PUT, POST, DELETE, OPTIONS, PATCH'
      response.headers['Access-Control-Max-Age'] = "1728000"
      response.headers['Access-Control-Allow-Headers'] = 'X-CSRF-Token, X-Requested-With, X-Prototype-Version, content-type, api-token, bzu-client-id'
    end

    # If this is a preflight OPTIONS request, then short-circuit the
    # request, return only the necessary headers and return an empty
    # text/plain.
    def cors_preflight_check
      if request.method == "OPTIONS"
        headers['Access-Control-Allow-Origin'] = '*'
        headers['Access-Control-Allow-Methods'] = 'GET, PUT, POST, DELETE, OPTIONS, PATCH'
        headers['Access-Control-Allow-Headers'] = 'X-CSRF-Token, X-Requested-With, X-Prototype-Version, content-type, api-token, bzu-client-id'
        headers['Access-Control-Max-Age'] = '1728000'
        render :text => '', :content_type => 'text/plain'
      end
    end

    def api_setup
      @params = params
      @request = request

      incoming_token = params[:api_token] || request.headers['api-token']

      api_token = ApiToken.find_by_token(incoming_token) if incoming_token

      credential = api_token.credential if api_token
      token = api_token.token if api_token
{'fraction_non_alphanumeric': 0.1123294998662744, 'fraction_numerical': 0.007488633324418294, 'mean_word_length': 3.5498783454987834, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2008251', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1124, 'n_words': 249}