Skip to content

Commit

Permalink
Accept responses with no etag header
Browse files Browse the repository at this point in the history
If the server does not provide an etag header, treat all responses as a
cache miss. This should allow 3rd party gem servers to more easily
provide compact_index results. /cc @mperham

See also sidekiq/sidekiq#4158.
  • Loading branch information
indirect committed Jul 29, 2020
1 parent 2a24d72 commit 8414706
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions bundler/lib/bundler/compact_index_client/updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ def update(local_path, remote_path, retrying = nil)
end
end

response_etag = (response["ETag"] || "").gsub(%r{\AW/}, "")
if etag_for(local_temp_path) == response_etag
etag = (response["ETag"] || "").gsub(%r{\AW/}, "")
if etag.length.zero? || etag_for(local_temp_path) == etag
SharedHelpers.filesystem_access(local_path) do
FileUtils.mv(local_temp_path, local_path)
end
return nil
end

if retrying
raise MisMatchedChecksumError.new(remote_path, response_etag, etag_for(local_temp_path))
raise MisMatchedChecksumError.new(remote_path, etag, etag_for(local_temp_path))
end

update(local_path, remote_path, :retrying)
Expand Down
12 changes: 5 additions & 7 deletions bundler/spec/bundler/compact_index_client/updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@

let(:response) { double(:response, :body => "") }

it "MisMatchedChecksumError is raised" do
it "treats the response as an update" do
# Twice: #update retries on failure
expect(response).to receive(:[]).with("Content-Encoding").twice { "" }
expect(response).to receive(:[]).with("ETag").twice { nil }
expect(fetcher).to receive(:call).twice { response }
expect(response).to receive(:[]).with("Content-Encoding") { "" }
expect(response).to receive(:[]).with("ETag") { nil }
expect(fetcher).to receive(:call) { response }

expect do
updater.update(local_path, remote_path)
end.to raise_error(Bundler::CompactIndexClient::Updater::MisMatchedChecksumError)
updater.update(local_path, remote_path)
end
end

Expand Down

0 comments on commit 8414706

Please sign in to comment.