diff --git a/Gemfile b/Gemfile index 9691dab..daeb69f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,2 @@ -source "http://gems.simplesideias.com.br" +source "http://rubygems.org" gem "rack", ">= 1.0.0" diff --git a/Gemfile.lock b/Gemfile.lock index 5d66fca..86fd1af 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GEM - remote: http://gems.simplesideias.com.br/ + remote: http://rubygems.org/ specs: - rack (1.2.2) + rack (1.4.1) PLATFORMS ruby diff --git a/rubygems_proxy.rb b/rubygems_proxy.rb index 5e77d1e..b32d4f6 100644 --- a/rubygems_proxy.rb +++ b/rubygems_proxy.rb @@ -24,7 +24,12 @@ def run when "/" [200, {"Content-Type" => "text/html"}, [erb(:index)]] else - [200, {"Content-Type" => "application/octet-stream"}, [contents]] + if env["QUERY_STRING"].empty? + [200, {"Content-Type" => "application/octet-stream"}, [contents]] + else + # add for query + [200, {"Content-Type" => "application/octet-stream"}, [query]] + end end rescue Exception [200, {"Content-Type" => "text/html"}, [erb(404)]] @@ -99,6 +104,23 @@ def contents open(filepath).read end + # add for query + def query + logger.info "Query from interwebz: #{api_url}" + open(api_url).read + rescue Exception => error + # Just try to load from file if something goes wrong. + # This includes HTTP timeout, or something. + # If it fails again, we won't have any files anyway! + logger.error "Error: #{error.class} => #{error.message}" + open(filepath).read + end + + # the query url + def api_url + File.join("http://rubygems.org", env["PATH_INFO"] + '?' + env["QUERY_STRING"]) + end + def save(contents) FileUtils.mkdir_p File.dirname(filepath) File.open(filepath, "wb") {|handler| handler << contents}