From e890bf2dccfb42b67e26ef53939296a824bb5813 Mon Sep 17 00:00:00 2001 From: nexus Date: Thu, 11 Jul 2013 08:53:38 -0500 Subject: [PATCH 1/2] Support proxy urls with query parameters --- .gitignore | 3 ++- rubygems_proxy.rb | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index ee21f4b..363aad3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ *.log restart.txt public/gems +public/api public/quick -*.gz \ No newline at end of file +*.gz diff --git a/rubygems_proxy.rb b/rubygems_proxy.rb index 5e77d1e..a939f58 100644 --- a/rubygems_proxy.rb +++ b/rubygems_proxy.rb @@ -2,6 +2,7 @@ require "fileutils" require "logger" require "erb" +require 'digest/sha1' class RubygemsProxy attr_reader :env @@ -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 @@ -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) @@ -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::SHA1.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 From 5ad9f7a8700f586b3b65c8d74a6ad71aad02b44f Mon Sep 17 00:00:00 2001 From: David McCullars Date: Tue, 15 Oct 2013 15:35:44 -0500 Subject: [PATCH 2/2] Time out dependencies cache, and use sha512 rather than sha1 --- rubygems_proxy.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rubygems_proxy.rb b/rubygems_proxy.rb index a939f58..5fb27dd 100644 --- a/rubygems_proxy.rb +++ b/rubygems_proxy.rb @@ -107,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 @@ -125,7 +125,7 @@ def filepath File.join(root_dir, env["PATH_INFO"]) else name = env["PATH_INFO"] - name = "#{name}___#{Digest::SHA1.hexdigest env["QUERY_STRING"]}" unless env["QUERY_STRING"].to_s == '' + name = "#{name}___#{Digest::SHA512.hexdigest env["QUERY_STRING"]}" unless env["QUERY_STRING"].to_s == '' File.join(cache_dir, name) end end