blob: 99bae039f0f4b7bfaa0f6b2adb5766313a59117a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# frozen_string_literal: true
require_relative "helpers/compact_index"
# The purpose of this Artifice is to test that an incremental response is ignored
# when the digest is not present to verify that the partial response is valid.
class CompactIndexPartialUpdateNoDigestNotIncremental < CompactIndexAPI
def partial_update_no_digest
response_body = yield
headers "Surrogate-Control" => "max-age=2592000, stale-while-revalidate=60"
content_type "text/plain"
requested_range_for(response_body)
end
get "/versions" do
partial_update_no_digest do
file = tmp("versions.list")
FileUtils.rm_f(file)
file = CompactIndex::VersionsFile.new(file.to_s)
file.create(gems)
lines = file.contents([], calculate_info_checksums: true).split("\n")
name, versions, checksum = lines.last.split(" ")
# shuffle versions so new versions are not appended to the end
[*lines[0..-2], [name, versions.split(",").reverse.join(","), checksum].join(" ")].join("\n")
end
end
get "/info/:name" do
partial_update_no_digest do
gem = gems.find {|g| g.name == params[:name] }
lines = CompactIndex.info(gem ? gem.versions : []).split("\n")
# shuffle versions so new versions are not appended to the end
[lines.first, lines.last, *lines[1..-2]].join("\n")
end
end
end
require_relative "helpers/artifice"
Artifice.activate_with(CompactIndexPartialUpdateNoDigestNotIncremental)
|