feat(registry,daemon): honour If-None-Match; allow offline deps resolution
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s

This commit is contained in:
faumaray committed 2026-12-04 05:44:26 +03:00
1 parent c6436a8010
commit fdfab9277b
8 files changed
+140 -19

No files matched your search

+23 -3
View File
@@ -30,6 +30,23 @@ Void::Result::Error make_error(Void::System::SystemErrorCode code, std::string m
return Void::System::make_system_error(code, std::move(msg));
}
// 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) {
return resp;
}
std::string etag = "\"" + Util::sha256_hex(resp.body).substr(0, 32) + "\"";
resp.headers["ETag"] = etag;
resp.headers["Cache-Control"] = "no-cache";
if (const auto inm = req.header("if-none-match"); inm && *inm == etag) {
HttpResponse not_modified;
not_modified.status = 304;
not_modified.headers["ETag"] = etag;
return not_modified;
}
return resp;
}
// Applies a single-range `Range: bytes=start-end` request to a download response. Always
// advertises Accept-Ranges; unsatisfiable or malformed ranges produce 416 with Content-Range.
HttpResponse apply_range(HttpResponse resp, std::string_view range_header) {
@@ -1037,7 +1054,7 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
return HttpResponse::error_json(404, "not_found", "release not found");
}
const auto &release = rit->second;
return HttpResponse::json(
HttpResponse detail = HttpResponse::json(
200, "{\"name\":" + json_quote(pkg_name) + ",\"version\":" +
json_quote(release.version) + ",\"sha256\":" + json_quote(release.sha256) +
",\"size_bytes\":" + std::to_string(release.size_bytes) +
@@ -1061,6 +1078,7 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
std::string{b.yanked ? "true" : "false"} + '}';
}) +
"}\n");
return with_etag(std::move(detail), req);
}
// Publish immutable release: PUT /api/v1/packages/<name>/<version>
@@ -1371,7 +1389,7 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
return HttpResponse::error_json(404, "not_found", "binary variant not found");
}
const auto &binary = bit->second;
return HttpResponse::json(
HttpResponse detail = HttpResponse::json(
200, "{\"variant_id\":" + json_quote(binary.variant_id) +
",\"sha256\":" + json_quote(binary.sha256) +
",\"size_bytes\":" + std::to_string(binary.size_bytes) +
@@ -1384,6 +1402,7 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
json_quote("/api/v1/packages/" + pkg_name + "/" + segs[4] + "/binaries/" +
segs[6] + "/download") +
"}\n");
return with_etag(std::move(detail), req);
}
// Download a prebuilt binary variant:
@@ -1435,7 +1454,7 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
if (rit == pit->second.releases.end()) {
return HttpResponse::error_json(404, "not_found", "release not found");
}
return HttpResponse::json(
HttpResponse detail = HttpResponse::json(
200,
"{\"binaries\":" + json_array(rit->second.binaries, [](const auto &entry) {
const auto &b = entry.second;
@@ -1449,6 +1468,7 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
: ",\"public_key\":" + json_quote(b.public_key)) +
'}';
}) + "}\n");
return with_etag(std::move(detail), req);
}
// Yank/unyank a binary variant: