зеркало из https://github.com/github/ruby.git
[rubygems/rubygems] Remove MD5 ETag generation from compact index
This was an offramp for generated etags to allow existing caches to be served until people could upgrade. It has been about 6 months since the transitional version was released, so we can remove this transitional code now. https://github.com/rubygems/rubygems/commit/4ec8cfe611
This commit is contained in:
Родитель
c96b5791ef
Коммит
76e31d9aa9
|
@ -86,11 +86,6 @@ module Bundler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# remove this method when we stop generating md5 digests for legacy etags
|
|
||||||
def md5
|
|
||||||
@digests && @digests["md5"]
|
|
||||||
end
|
|
||||||
|
|
||||||
def digests?
|
def digests?
|
||||||
@digests&.any?
|
@digests&.any?
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,7 +28,6 @@ module Bundler
|
||||||
|
|
||||||
CacheFile.copy(local_path) do |file|
|
CacheFile.copy(local_path) do |file|
|
||||||
etag = etag_path.read.tap(&:chomp!) if etag_path.file?
|
etag = etag_path.read.tap(&:chomp!) if etag_path.file?
|
||||||
etag ||= generate_etag(etag_path, file) # Remove this after 2.5.0 has been out for a while.
|
|
||||||
|
|
||||||
# Subtract a byte to ensure the range won't be empty.
|
# Subtract a byte to ensure the range won't be empty.
|
||||||
# Avoids 416 (Range Not Satisfiable) responses.
|
# Avoids 416 (Range Not Satisfiable) responses.
|
||||||
|
@ -67,16 +66,6 @@ module Bundler
|
||||||
etag_path.read.tap(&:chomp!) if etag_path.file?
|
etag_path.read.tap(&:chomp!) if etag_path.file?
|
||||||
end
|
end
|
||||||
|
|
||||||
# When first releasing this opaque etag feature, we want to generate the old MD5 etag
|
|
||||||
# based on the content of the file. After that it will always use the saved opaque etag.
|
|
||||||
# This transparently saves existing users with good caches from updating a bunch of files.
|
|
||||||
# Remove this behavior after 2.5.0 has been out for a while.
|
|
||||||
def generate_etag(etag_path, file)
|
|
||||||
etag = file.md5.hexdigest
|
|
||||||
CacheFile.write(etag_path, etag)
|
|
||||||
etag
|
|
||||||
end
|
|
||||||
|
|
||||||
def etag_from_response(response)
|
def etag_from_response(response)
|
||||||
return unless response["ETag"]
|
return unless response["ETag"]
|
||||||
etag = response["ETag"].delete_prefix("W/")
|
etag = response["ETag"].delete_prefix("W/")
|
||||||
|
|
|
@ -119,23 +119,7 @@ RSpec.describe Bundler::CompactIndexClient::Updater do
|
||||||
|
|
||||||
context "without an etag file" do
|
context "without an etag file" do
|
||||||
let(:headers) do
|
let(:headers) do
|
||||||
{
|
{ "Range" => "bytes=2-" }
|
||||||
"Range" => "bytes=2-",
|
|
||||||
# This MD5 feature should be deleted after sufficient time has passed since release.
|
|
||||||
# From then on, requests that still don't have a saved etag will be made without this header.
|
|
||||||
"If-None-Match" => %("#{Digest::MD5.hexdigest(local_body)}"),
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
it "saves only the etag_path if generated etag matches" do
|
|
||||||
expect(fetcher).to receive(:call).once.with(remote_path, headers).and_return(response)
|
|
||||||
allow(response).to receive(:is_a?).with(Gem::Net::HTTPPartialContent) { false }
|
|
||||||
allow(response).to receive(:is_a?).with(Gem::Net::HTTPNotModified) { true }
|
|
||||||
|
|
||||||
updater.update(remote_path, local_path, etag_path)
|
|
||||||
|
|
||||||
expect(local_path.read).to eq("abc")
|
|
||||||
expect(%("#{etag_path.read}")).to eq(headers["If-None-Match"])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "appends the file" do
|
it "appends the file" do
|
||||||
|
|
Загрузка…
Ссылка в новой задаче