<commit_before>require 'sinatra'
require 'base64'
require 'json'
require 'vcr'
require 'nokogiri'
require 'webmock'
require 'cybersourcery'
require 'cybersourcery_testing/vcr'
require ARGV[0] # path to cybersourcery initializer

CybersourceryTesting::Vcr.configure

get('/') { "It's not a trick it's an illusion" }

get '/*' do |path|
  proxy_request do |uri|
    Net::HTTP.get_response(uri)
  end
end

post '/*' do |path|
  uri = URI "#{Cybersourcery.configuration.sop_test_url}/#{path}"
  response = nil

  if Cybersourcery.configuration.use_vcr_in_tests
    VCR.use_cassette('cybersourcery',
      record: :new_episodes,
      match_requests_on: %i(method uri card_number_equality)) do
        response = Net::HTTP.post_form(uri, params)
      end
  else
     response = Net::HTTP.post_form(uri, params)
  end

  code     = response.code.to_i
  type     = response.content_type
  body     = response.body
  [code, { 'Content-Type' => type }, body]
end<commit_msg>handle get requests correctly (so favicon requests don't throw errors)<commit_after>require 'sinatra'
require 'base64'
require 'json'
require 'vcr'
require 'nokogiri'
require 'webmock'
require 'cybersourcery'
require 'cybersourcery_testing/vcr'
require ARGV[0] # path to cybersourcery initializer

CybersourceryTesting::Vcr.configure

get('/') { "It's not a trick it's an illusion" }

get '/*' do |path|
  response = Net::HTTP.get_response(URI uri)
  code     = response.code.to_i
  type     = response.content_type
  body     = response.body
  [code, { 'Content-Type' => type }, body]
end

post '/*' do |path|
  uri = URI "#{Cybersourcery.configuration.sop_test_url}/#{path}"
  response = nil

  if Cybersourcery.configuration.use_vcr_in_tests
    VCR.use_cassette('cybersourcery',
      record: :new_episodes,
      match_requests_on: %i(method uri card_number_equality)) do
        response = Net::HTTP.post_form(uri, params)
      end
  else
     response = Net::HTTP.post_form(uri, params)
  end

  code     = response.code.to_i
  type     = response.content_type
  body     = response.body
  [code, { 'Content-Type' => type }, body]
end
{'fraction_non_alphanumeric': 0.11954459203036052, 'fraction_numerical': 0.0028462998102466793, 'mean_word_length': 3.974056603773585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5094945', 'n_tokens_mistral': 750, 'n_tokens_neox': 735, 'n_words': 172}