Skip to content

Commit 19bdcc8

Browse files
martinemdehsbt
authored andcommitted
[rubygems/rubygems] Retry gracefully on blank partial response in compact index
ruby/rubygems@fafb9ae090
1 parent 223f37c commit 19bdcc8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/bundler/compact_index_client/updater.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def append(remote_path, local_path, etag_path)
3737
file.digests = parse_digests(response)
3838
# server may ignore Range and return the full response
3939
if response.is_a?(Gem::Net::HTTPPartialContent)
40-
break false unless file.append(response.body.byteslice(1..-1))
40+
tail = response.body.byteslice(1..-1)
41+
break false unless tail && file.append(tail)
4142
else
4243
file.write(response.body)
4344
end

spec/bundler/bundler/compact_index_client/updater_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@
115115
expect(local_path.read).to eq(full_body)
116116
expect(etag_path.read).to eq("NewEtag")
117117
end
118+
119+
it "tries the request again if the partial response is blank" do
120+
allow(response).to receive(:[]).with("Repr-Digest") { "sha-256=:baddigest:" }
121+
allow(response).to receive(:body) { "" }
122+
allow(response).to receive(:is_a?).with(Gem::Net::HTTPPartialContent) { true }
123+
expect(fetcher).to receive(:call).once.with(remote_path, headers).and_return(response)
124+
125+
full_response = double(:full_response, body: full_body, is_a?: false)
126+
allow(full_response).to receive(:[]).with("Repr-Digest") { "sha-256=:#{digest}:" }
127+
allow(full_response).to receive(:[]).with("ETag") { '"NewEtag"' }
128+
expect(fetcher).to receive(:call).once.with(remote_path, { "If-None-Match" => '"LocalEtag"' }).and_return(full_response)
129+
130+
updater.update(remote_path, local_path, etag_path)
131+
132+
expect(local_path.read).to eq(full_body)
133+
expect(etag_path.read).to eq("NewEtag")
134+
end
118135
end
119136

120137
context "without an etag file" do

0 commit comments

Comments
 (0)