feat(net): route the remote action cache through Void::Net when available
This commit is contained in:
1 parent
5de0146e83
commit
1c2f7d9a2c
5 files changed
+55
-3
No files matched your search
@@ -5,6 +5,9 @@
|
||||
#include <Void/Core/Scope.hpp>
|
||||
#include <Void/System/Types.hpp>
|
||||
#include <Void/Text/Str.hpp>
|
||||
#if defined(VBS_HAS_VOID_NET)
|
||||
#include <Void/Net/Http.hpp>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -105,6 +108,37 @@ http_exchange(const ParsedUrl &parsed, std::string_view method, std::string_view
|
||||
std::string_view body) {
|
||||
const std::string full_path = parsed.base_path + std::string{path};
|
||||
|
||||
#if defined(VBS_HAS_VOID_NET)
|
||||
// Track E4: Void::Net handles http:// and verified TLS https:// for the shared cache.
|
||||
Void::Net::Request request;
|
||||
if (method == "GET") {
|
||||
request.method = Void::Net::Method::Get;
|
||||
} else if (method == "PUT") {
|
||||
request.method = Void::Net::Method::Put;
|
||||
} else if (method == "POST") {
|
||||
request.method = Void::Net::Method::Post;
|
||||
} else if (method == "DELETE") {
|
||||
request.method = Void::Net::Method::Delete;
|
||||
} else if (method == "HEAD") {
|
||||
request.method = Void::Net::Method::Head;
|
||||
}
|
||||
request.url = std::format("{}://{}:{}{}", parsed.scheme, parsed.host, parsed.port, full_path);
|
||||
for (const auto &[name, value] : headers) {
|
||||
request.headers.push_back(Void::Net::Header{name, value});
|
||||
}
|
||||
if (!body.empty()) {
|
||||
request.body = std::string{body};
|
||||
}
|
||||
request.timeout = std::chrono::seconds{60};
|
||||
const Void::Net::HttpClient client = Void::Net::HttpClient::secure();
|
||||
auto response = client.send(request);
|
||||
if (!response) {
|
||||
return std::unexpected{make_error(
|
||||
Void::System::SystemErrorCode::io_error,
|
||||
std::format("remote cache: Void::Net request failed: {}", response.error().message()))};
|
||||
}
|
||||
return HttpReply{response->status, std::move(response->body)};
|
||||
#else
|
||||
if (parsed.scheme == "http") {
|
||||
struct addrinfo hints{};
|
||||
hints.ai_family = AF_INET;
|
||||
@@ -223,6 +257,7 @@ http_exchange(const ParsedUrl &parsed, std::string_view method, std::string_view
|
||||
reply.body = proc->stdout_data.substr(0, nl);
|
||||
}
|
||||
return reply;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::map<std::string, std::string, std::less<>> auth_headers(const RemoteCacheConfig &config) {
|
||||
|
||||
Reference in new issue
Block a user