feat(net): adopt Void::Net for the registry HTTP transport when available
This commit is contained in:
1 parent
7fd8fe9f6d
commit
b69a7d1516
7 files changed
+79
-3
No files matched your search
@@ -13,6 +13,9 @@
|
||||
#include <Void/Text/Semver.hpp>
|
||||
#include <Void/Text/Str.hpp>
|
||||
#include <Void/Text/Url.hpp>
|
||||
#if defined(VBS_HAS_VOID_NET)
|
||||
#include <Void/Net/Http.hpp>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <arpa/inet.h>
|
||||
@@ -111,6 +114,44 @@ send_http_request(const ParsedHttpUrl &parsed, std::string_view method, std::str
|
||||
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 transport handles both http:// and verified TLS https://.
|
||||
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 {
|
||||
request.method = Void::Net::Method::Get;
|
||||
}
|
||||
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{30};
|
||||
const Void::Net::HttpClient net_client = Void::Net::HttpClient::secure();
|
||||
auto net_response = net_client.send(request);
|
||||
if (!net_response) {
|
||||
return std::unexpected{
|
||||
make_error(Void::System::SystemErrorCode::io_error,
|
||||
std::format("registry client: Void::Net request failed: {}",
|
||||
net_response.error().message()))};
|
||||
}
|
||||
RawHttpReply net_reply;
|
||||
net_reply.status = net_response->status;
|
||||
for (const auto &header : net_response->headers) {
|
||||
net_reply.headers[Void::Str::to_lower_ascii(header.name)] = header.value;
|
||||
}
|
||||
net_reply.body = std::move(net_response->body);
|
||||
return net_reply;
|
||||
#else
|
||||
// Plain TCP HTTP/1.1 client for http:// (loopback/local registry without external deps).
|
||||
if (parsed.scheme == "http") {
|
||||
struct addrinfo hints{};
|
||||
@@ -249,6 +290,7 @@ send_http_request(const ParsedHttpUrl &parsed, std::string_view method, std::str
|
||||
reply.body = proc->stdout_data.substr(0, nl);
|
||||
}
|
||||
return reply;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string get_str(const JsonVal::Object &obj, const std::string &k) {
|
||||
|
||||
Reference in new issue
Block a user