<commit_before>class Hostess < Sinatra::Base
  cattr_writer :local

  def self.local
    @@local ||= false
  end

  def serve
    if self.class.local
      send_file(Pusher.server_path(request.path_info))
    else
      yield
    end
  end

  def serve_via_s3
    serve do
      redirect VaultObject.s3_url_for(request.path_info)
    end
  end

  def serve_via_cf
    serve do
      redirect VaultObject.cf_url_for(request.path_info)
    end
  end

  %w[/specs.4.8.gz
     /latest_specs.4.8.gz
     /prerelease_specs.4.8.gz
  ].each do |index|
    get index do
      content_type('application/x-gzip')
      serve_via_s3
    end
  end

  %w[/quick/Marshal.4.8/*.gemspec.rz
     /quick/rubygems-update-1.3.6.gemspec.rz
     /yaml.Z
     /yaml.z
     /Marshal.4.8.Z
     /quick/index.rz
     /quick/latest_index.rz
  ].each do |deflated_index|
    get deflated_index do
      content_type('application/x-deflate')
      serve_via_s3
    end
  end

  %w[/yaml
     /Marshal.4.8
     /specs.4.8
     /latest_specs.4.8
     /prerelease_specs.4.8
     /quick/index
     /quick/latest_index
  ].each do |old_index|
    head old_index do
      "Please upgrade your RubyGems, it's quite old: http://rubygems.org/pages/download"
    end

    get old_index do
      serve_via_s3
    end
  end

  get "/gems/*.gem" do
    full_name = params[:splat].to_s.chomp(".gem")

    if Rails.env.maintenance?
      serve_via_cf
    else
      if version = Version.find_by_full_name(full_name)
        Download.incr(version)

        serve_via_cf
      else
        error 400, "This gem does not currently live at Gemcutter."
      end
    end
  end

  get "/downloads/*.gem" do
    redirect "/gems/#{params[:splat]}.gem"
  end
end<commit_msg>Returning 404 for bad gems, now that the cascade allows it<commit_after>class Hostess < Sinatra::Base
  cattr_writer :local

  def self.local
    @@local ||= false
  end

  def serve
    if self.class.local
      send_file(Pusher.server_path(request.path_info))
    else
      yield
    end
  end

  def serve_via_s3
    serve do
      redirect VaultObject.s3_url_for(request.path_info)
    end
  end

  def serve_via_cf
    serve do
      redirect VaultObject.cf_url_for(request.path_info)
    end
  end

  %w[/specs.4.8.gz
     /latest_specs.4.8.gz
     /prerelease_specs.4.8.gz
  ].each do |index|
    get index do
      content_type('application/x-gzip')
      serve_via_s3
    end
  end

  %w[/quick/Marshal.4.8/*.gemspec.rz
     /quick/rubygems-update-1.3.6.gemspec.rz
     /yaml.Z
     /yaml.z
     /Marshal.4.8.Z
     /quick/index.rz
     /quick/latest_index.rz
  ].each do |deflated_index|
    get deflated_index do
      content_type('application/x-deflate')
      serve_via_s3
    end
  end

  %w[/yaml
     /Marshal.4.8
     /specs.4.8
     /latest_specs.4.8
     /prerelease_specs.4.8
     /quick/index
     /quick/latest_index
  ].each do |old_index|
    head old_index do
      "Please upgrade your RubyGems, it's quite old: http://rubygems.org/pages/download"
    end

    get old_index do
      serve_via_s3
    end
  end

  get "/gems/*.gem" do
    full_name = params[:splat].to_s.chomp(".gem")

    if Rails.env.maintenance?
      serve_via_cf
    else
      if version = Version.find_by_full_name(full_name)
        Download.incr(version)

        serve_via_cf
      else
        error 404, "This gem does not currently live at Gemcutter."
      end
    end
  end

  get "/downloads/*.gem" do
    redirect "/gems/#{params[:splat]}.gem"
  end
end
{'fraction_non_alphanumeric': 0.10186513629842181, 'fraction_numerical': 0.017503586800573886, 'mean_word_length': 2.1662125340599454, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4006007', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1292, 'n_words': 265}