feat(registry,daemon): ETag downloads; report pending changes
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 11s

This commit is contained in:
faumaray committed 2026-12-04 05:57:16 +03:00
1 parent fdfab9277b
commit 85ff7a8c75
8 files changed
+65 -3

No files matched your search

+24
View File
@@ -30,6 +30,22 @@ Void::Result::Error make_error(Void::System::SystemErrorCode code, std::string m
return Void::System::make_system_error(code, std::move(msg));
}
// Returns a bodyless 304 when the request's If-None-Match matches the artifact digest.
std::optional<HttpResponse> not_modified_for(const HttpRequest &req, const std::string &digest) {
const auto inm = req.header("if-none-match");
if (!inm) {
return std::nullopt;
}
const std::string etag = "\"" + digest + "\"";
if (*inm != etag && *inm != digest) {
return std::nullopt;
}
HttpResponse resp;
resp.status = 304;
resp.headers["ETag"] = etag;
return resp;
}
// Adds a strong ETag to a cacheable 200 response and honours If-None-Match with 304.
HttpResponse with_etag(HttpResponse resp, const HttpRequest &req) {
if (resp.status != 200) {
@@ -1235,6 +1251,9 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
if (rit == pit->second.releases.end()) {
return HttpResponse::error_json(404, "not_found", "release not found");
}
if (auto not_modified = not_modified_for(req, rit->second.sha256)) {
return *not_modified;
}
const auto bpath = blob_path(rit->second.sha256);
auto bytes = Void::FileSystem::read_file_bounded(bpath, {256ULL * 1024ULL * 1024ULL});
if (!bytes || Util::sha256_hex(*bytes) != rit->second.sha256) {
@@ -1245,6 +1264,7 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
resp.status = 200;
resp.headers["Content-Type"] = "application/x-tar";
resp.headers["X-Content-SHA256"] = rit->second.sha256;
resp.headers["ETag"] = "\"" + rit->second.sha256 + "\"";
resp.body = std::move(*bytes);
const auto range = req.header("range");
return apply_range(std::move(resp), range ? *range : std::string_view{});
@@ -1425,6 +1445,9 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
if (bit == rit->second.binaries.end()) {
return HttpResponse::error_json(404, "not_found", "binary variant not found");
}
if (auto not_modified = not_modified_for(req, bit->second.sha256)) {
return *not_modified;
}
const auto bpath = blob_path(bit->second.sha256);
auto bytes = Void::FileSystem::read_file_bounded(bpath, {256ULL * 1024ULL * 1024ULL});
if (!bytes || Util::sha256_hex(*bytes) != bit->second.sha256) {
@@ -1435,6 +1458,7 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
resp.status = 200;
resp.headers["Content-Type"] = "application/octet-stream";
resp.headers["X-Content-SHA256"] = bit->second.sha256;
resp.headers["ETag"] = "\"" + bit->second.sha256 + "\"";
resp.body = std::move(*bytes);
const auto range = req.header("range");
return apply_range(std::move(resp), range ? *range : std::string_view{});