summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAgis Anastasopoulos <agis.anast@gmail.com>2015-10-20 15:24:43 +0300
committerAgis Anastasopoulos <agis.anast@gmail.com>2015-10-20 19:52:49 +0300
commit2b029f25354d08f9e5e42a4bb07c99a636e140bd (patch)
treeabb4482d91e93ede6ed23863a785c53ad5be5d67
parentc95d283702bea53a4fee2193b4832a1ce0d0bacd (diff)
downloadbundler-original-source-header.tar.gz
Set X-Gemfile-Source when fetching gemsoriginal-source-header
Since gemstash will only support RubyGems >= 2.4 (bundler/gemstash#32), we only set this header in RubyGems 2.0+.
-rw-r--r--.rubocop_todo.yml1
-rw-r--r--lib/bundler/rubygems_integration.rb3
-rw-r--r--spec/realworld/gemfile_source_header_spec.rb63
-rw-r--r--spec/support/artifice/endpoint_mirror_source.rb13
4 files changed, 79 insertions, 1 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index b674f399bb..7269f36893 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -256,6 +256,7 @@ Style/RescueModifier:
- 'lib/bundler/fetcher.rb'
- 'lib/bundler/resolver.rb'
- 'spec/realworld/dependency_api_spec.rb'
+ - 'spec/realworld/gemfile_source_header_spec.rb'
# Offense count: 1
# Configuration parameters: Methods.
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index b5ae60d5ed..9750d98bb3 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -586,7 +586,8 @@ module Bundler
uri = Bundler.settings.mirror_for(uri)
proxy = configuration[:http_proxy]
dns = Resolv::DNS.new
- fetcher = Gem::RemoteFetcher.new(proxy, dns)
+ fetcher = Bundler::GemRemoteFetcher.new(proxy, dns)
+ fetcher.headers = { "X-Gemfile-Source" => spec.remote.original_uri.to_s } if spec.remote.original_uri
fetcher.download(spec, uri, path)
end
diff --git a/spec/realworld/gemfile_source_header_spec.rb b/spec/realworld/gemfile_source_header_spec.rb
new file mode 100644
index 0000000000..aff127db6c
--- /dev/null
+++ b/spec/realworld/gemfile_source_header_spec.rb
@@ -0,0 +1,63 @@
+require "spec_helper"
+require "thread"
+
+describe "fetching dependencies with a mirrored source", :rubygems => ">= 2.0" do
+ let(:mirror) { "https://server.example.org" }
+ let(:original) { "http://127.0.0.1:#{@port}" }
+
+ before do
+ setup_server
+ bundle "config --local mirror.#{mirror} #{original}"
+ end
+
+ after { @t.kill }
+
+ it "sets the 'X-Gemfile-Source' header and bundles successfully" do
+ gemfile <<-G
+ source "#{mirror}"
+ gem 'weakling'
+ G
+
+ bundle :install
+
+ expect(out).to include("Installing weakling")
+ expect(out).to include("Bundle complete")
+ should_be_installed "weakling 0.0.3"
+ end
+
+ private
+
+ def setup_server
+ # need to hack, so we can require rack
+ old_gem_home = ENV["GEM_HOME"]
+ ENV["GEM_HOME"] = Spec::Path.base_system_gems.to_s
+ require "rack"
+ ENV["GEM_HOME"] = old_gem_home
+
+ @port = 21_459
+ @port += 1 while TCPSocket.new("127.0.0.1", @port) rescue false
+ @server_uri = "http://127.0.0.1:#{@port}"
+
+ require File.expand_path("../../support/artifice/endpoint_mirror_source", __FILE__)
+
+ @t = Thread.new {
+ Rack::Server.start(:app => EndpointMirrorSource,
+ :Host => "0.0.0.0",
+ :Port => @port,
+ :server => "webrick",
+ :AccessLog => [])
+ }.run
+
+ wait_for_server(@port)
+ end
+
+ def wait_for_server(port, seconds = 15)
+ tries = 0
+ sleep 0.5
+ TCPSocket.new("127.0.0.1", port)
+ rescue => e
+ raise(e) if tries > (seconds * 2)
+ tries += 1
+ retry
+ end
+end
diff --git a/spec/support/artifice/endpoint_mirror_source.rb b/spec/support/artifice/endpoint_mirror_source.rb
new file mode 100644
index 0000000000..39cd3656fa
--- /dev/null
+++ b/spec/support/artifice/endpoint_mirror_source.rb
@@ -0,0 +1,13 @@
+require File.expand_path("../endpoint", __FILE__)
+
+class EndpointMirrorSource < Endpoint
+ get "/gems/:id" do
+ if request.env["HTTP_X_GEMFILE_SOURCE"] == "https://server.example.org/"
+ File.read("#{gem_repo1}/gems/#{params[:id]}")
+ else
+ halt 500
+ end
+ end
+end
+
+Artifice.activate_with(EndpointMirrorSource)