Skip to content
This repository was archived by the owner on Sep 25, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
*.log
restart.txt
public/gems
public/api
public/quick
*.gz
*.gz
19 changes: 11 additions & 8 deletions rubygems_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "fileutils"
require "logger"
require "erb"
require 'digest/sha1'

class RubygemsProxy
attr_reader :env
Expand All @@ -16,11 +17,11 @@ def initialize(env)
end

def run
logger.info "#{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}"
logger.info "#{env["REQUEST_METHOD"]} #{env["REQUEST_URI"]}"

return update_specs if env["REQUEST_METHOD"] == "DELETE"

case env["PATH_INFO"]
case env["REQUEST_URI"]
when "/"
[200, {"Content-Type" => "text/html"}, [erb(:index)]]
else
Expand All @@ -36,7 +37,7 @@ def erb(view)
end

def server_url
env["rack.url_scheme"] + "://" + File.join(env["SERVER_NAME"], env["PATH_INFO"])
env["rack.url_scheme"] + "://" + File.join(env["SERVER_NAME"], env["REQUEST_URI"])
end

def rubygems_url(gemname)
Expand Down Expand Up @@ -106,8 +107,8 @@ def save(contents)

def cached?
case File.basename(filepath)
when /^specs\./
File.exist?(filepath) && (Time.now - File.mtime(filepath)).to_i < 84600
when /^specs\./, /^dependencies___/
File.file?(filepath) && (Time.now - File.mtime(filepath)).to_i < 84600
when /\.gz$/
false
else
Expand All @@ -116,19 +117,21 @@ def cached?
end

def specs?
env["PATH_INFO"] =~ /specs\..+\.gz$/
env["REQUEST_URI"] =~ /specs\..+\.gz$/
end

def filepath
if specs?
File.join(root_dir, env["PATH_INFO"])
else
File.join(cache_dir, env["PATH_INFO"])
name = env["PATH_INFO"]
name = "#{name}___#{Digest::SHA512.hexdigest env["QUERY_STRING"]}" unless env["QUERY_STRING"].to_s == ''
File.join(cache_dir, name)
end
end

def url
File.join("http://rubygems.org", env["PATH_INFO"])
File.join("http://rubygems.org", env["REQUEST_URI"])
end

def update_specs
Expand Down