<commit_before>require 'libraries'

module Hurl
  def self.redis
    @redis
  end

  def self.redis=(redis)
    @redis = redis
  end

  class App < Sinatra::Base
    dir = File.dirname(File.expand_path(__FILE__))

    set :views,  "#{dir}/views"
    set :public, "#{dir}/public"
    set :static, true

    def initialize(*args)
      super
      Hurl.redis = Redis.new(:host => '127.0.0.1', :port => 6379)
    end

    def redis
      Hurl.redis
    end


    #
    # routes
    #

    get '/' do
      erb :index
    end

    get '/about/' do
      erb :about
    end

    post '/signup/' do
      email, password = params.values_at(:email, :password)
      user = User.create(:email => email, :password => password)

      if user.valid?
        "sweet!"
      else
        json :error => user.errors.to_s
      end
    end

    post '/' do
      url, method, auth = params.values_at(:url, :method, :auth)
      curl = Curl::Easy.new(url)

      requests = []
      curl.on_debug do |type, data|
        # track request headers
        requests << data if type == Curl::CURLINFO_HEADER_OUT
      end

      curl.follow_location = true if params[:follow_redirects]

      # ensure a method is set
      method = method.to_s.empty? ? 'GET' : method

      # update auth
      add_auth(auth, curl, params)

      # arbitrary headers
      add_headers_from_arrays(curl, params["header-keys"], params["header-vals"])

      # arbitrary params<commit_msg>method should be upcase'd<commit_after>require 'libraries'

module Hurl
  def self.redis
    @redis
  end

  def self.redis=(redis)
    @redis = redis
  end

  class App < Sinatra::Base
    dir = File.dirname(File.expand_path(__FILE__))

    set :views,  "#{dir}/views"
    set :public, "#{dir}/public"
    set :static, true

    def initialize(*args)
      super
      Hurl.redis = Redis.new(:host => '127.0.0.1', :port => 6379)
    end

    def redis
      Hurl.redis
    end


    #
    # routes
    #

    get '/' do
      erb :index
    end

    get '/about/' do
      erb :about
    end

    post '/signup/' do
      email, password = params.values_at(:email, :password)
      user = User.create(:email => email, :password => password)

      if user.valid?
        "sweet!"
      else
        json :error => user.errors.to_s
      end
    end

    post '/' do
      url, method, auth = params.values_at(:url, :method, :auth)
      curl = Curl::Easy.new(url)

      requests = []
      curl.on_debug do |type, data|
        # track request headers
        requests << data if type == Curl::CURLINFO_HEADER_OUT
      end

      curl.follow_location = true if params[:follow_redirects]

      # ensure a method is set
      method = (method.to_s.empty? ? 'GET' : method).upcaes

      # update auth
      add_auth(auth, curl, params)

      # arbitrary headers
      add_headers_from_arrays(curl, params["header-keys"], params["header-vals"])

      # arbitrary params
{'fraction_non_alphanumeric': 0.12179267875470406, 'fraction_numerical': 0.006842285323297981, 'mean_word_length': 2.140708915145005, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5666474', 'n_tokens_mistral': 1002, 'n_tokens_neox': 948, 'n_words': 246}