Skip to content

Commit 5df1553

Browse files
Record ETag and Last-Modified for each URL
Co-authored-by: Alex Arslan <ararslan@comcast.net>
1 parent 37e40a2 commit 5df1553

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/VersionsJSONUtil.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using HTTP, JSON, Pkg.BinaryPlatforms, WebCacheUtilities, SHA, Lazy
44
using Tar: Tar
55
import Pkg.BinaryPlatforms: triplet, arch
66
import Pkg.PlatformEngines: exe7z
7+
using URIs: URIs, URI
78

89
"Wrapper types to define three jlext methods for portable, tarball and installer Windows"
910
struct WindowsPortable
@@ -143,6 +144,31 @@ function get_tags()
143144
JSON.parse(String(read(tags_json_path)))
144145
end
145146

147+
##### --------------------------------------------------------------------------------------
148+
##### Get ETag and Last-Modified, so we know if we need to re-download and re-checksum files
149+
150+
Base.@kwdef struct HeadInfo
151+
url::URI
152+
etag::Union{String, Nothing}
153+
last_modified::Union{String, Nothing}
154+
end
155+
156+
function HeadInfo(url)
157+
local response = nothing
158+
try
159+
response = HTTP.head(url)
160+
catch
161+
error("Encountered error when making HEAD request to URL: $url")
162+
end
163+
etag = HTTP.header(response, "ETag", nothing)
164+
etag === nothing && @warn "ETag not provided in response from $url"
165+
last_modified = HTTP.header(response, "Last-Modified", nothing)
166+
last_modified === nothing && @warn "Last-Modified not provided in response from $url"
167+
return HeadInfo(; url=URI(url), etag, last_modified)
168+
end
169+
170+
##### --------------------------------------------------------------------------------------
171+
146172
function main(out_path)
147173
tags = get_tags()
148174
tag_versions = filter(x -> x !== nothing, [vnum_maybe(basename(t["ref"])) for t in tags])
@@ -240,6 +266,8 @@ function main(out_path)
240266

241267
end
242268

269+
headinfo = HeadInfo(url)
270+
243271
# Build up metadata about this file
244272
file_dict = Dict(
245273
"triplet" => triplet(platform),
@@ -260,6 +288,13 @@ function main(out_path)
260288
file_dict["asc"] = asc_signature
261289
end
262290

291+
if !isnothing(headinfo.etag)
292+
file_dict["etag"] = headinfo.etag
293+
end
294+
if !isnothing(headinfo.last_modified)
295+
file_dict["last-modified"] = headinfo.last_modified
296+
end
297+
263298
# Right now, all we have are archives, but let's be forward-thinking
264299
# and make this an array of dictionaries that is easy to extensibly match
265300
push!(meta[version]["files"], file_dict)

test/more_tests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ end
6767
]
6868
optional_keys = [
6969
"asc",
70+
"etag",
7071
"git-tree-sha1",
7172
"git-tree-sha256",
73+
"last-modified",
7274
]
7375
allowed_keys = union(required_keys, optional_keys)
7476
@test required_keys collect(keys(filedict))

0 commit comments

Comments
 (0)