aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver-test/zenserver-test.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-03-10 17:27:26 +0100
committerGitHub Enterprise <[email protected]>2026-03-10 17:27:26 +0100
commitd0a07e555577dcd4a8f55f1b45d9e8e4e6366ab7 (patch)
tree2dfe1e3e0b620043d358e0b7f8bdf8320d985491 /src/zenserver-test/zenserver-test.cpp
parentchangelog entry which was inadvertently omitted from PR merge (diff)
downloadzen-d0a07e555577dcd4a8f55f1b45d9e8e4e6366ab7.tar.xz
zen-d0a07e555577dcd4a8f55f1b45d9e8e4e6366ab7.zip
HttpClient using libcurl, Unix Sockets for HTTP. HTTPS support (#770)
The main goal of this change is to eliminate the cpr back-end altogether and replace it with the curl implementation. I would expect to drop cpr as soon as we feel happy with the libcurl back-end. That would leave us with a direct dependency on libcurl only, and cpr can be eliminated as a dependency. ### HttpClient Backend Overhaul - Implemented a new **libcurl-based HttpClient** backend (`httpclientcurl.cpp`, ~2000 lines) as an alternative to the cpr-based one - Made HttpClient backend **configurable at runtime** via constructor arguments and `-httpclient=...` CLI option (for zen, zenserver, and tests) - Extended HttpClient test suite to cover multipart/content-range scenarios ### Unix Domain Socket Support - Added Unix domain socket support to **httpasio** (server side) - Added Unix domain socket support to **HttpClient** - Added Unix domain socket support to **HttpWsClient** (WebSocket client) - Templatized `HttpServerConnectionT<SocketType>` and `WsAsioConnectionT<SocketType>` to handle TCP, Unix, and SSL sockets uniformly via `if constexpr` dispatch ### HTTPS Support - Added **preliminary HTTPS support to httpasio** (for Mac/Linux via OpenSSL) - Added **basic HTTPS support for http.sys** (Windows) - Implemented HTTPS test for httpasio - Split `InitializeServer` into smaller sub-functions for http.sys ### Other Notable Changes - Improved **zenhttp-test stability** with dynamic port allocation - Enhanced port retry logic in http.sys (handles ERROR_ACCESS_DENIED) - Fatal signal/exception handlers for backtrace generation in tests - Added `zen bench http` subcommand to exercise network + HTTP client/server communication stack
Diffstat (limited to 'src/zenserver-test/zenserver-test.cpp')
-rw-r--r--src/zenserver-test/zenserver-test.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/zenserver-test/zenserver-test.cpp b/src/zenserver-test/zenserver-test.cpp
index 8d5400294..0b2bc50c0 100644
--- a/src/zenserver-test/zenserver-test.cpp
+++ b/src/zenserver-test/zenserver-test.cpp
@@ -24,6 +24,10 @@
# include <atomic>
# include <filesystem>
+ZEN_THIRD_PARTY_INCLUDES_START
+# include <asio.hpp>
+ZEN_THIRD_PARTY_INCLUDES_END
+
# if ZEN_PLATFORM_WINDOWS
# include <ppl.h>
# include <process.h>
@@ -109,6 +113,11 @@ main(int argc, char** argv)
ServerClass = argv[++i];
}
}
+ else if (std::string_view Arg(argv[i]); Arg.starts_with("--httpclient="sv))
+ {
+ std::string_view Value = Arg.substr(13);
+ zen::SetDefaultHttpClientBackend(Value);
+ }
else if (argv[i] == "--verbose"sv)
{
Verbose = true;
@@ -341,6 +350,38 @@ TEST_CASE("http.package")
CHECK_EQ(ResponsePackage, TestPackage);
}
+# if defined(ASIO_HAS_LOCAL_SOCKETS)
+TEST_CASE("http.unixsocket")
+{
+ std::filesystem::path TestDir = TestEnv.CreateNewTestDir();
+ std::filesystem::path SocketDir = TestEnv.CreateNewTestDir();
+ std::string SocketPath = (SocketDir / "zen.sock").string();
+
+ ZenServerInstance Instance(TestEnv);
+ Instance.SetDataDir(TestDir);
+ const uint16_t PortNumber = Instance.SpawnServerAndWaitUntilReady(fmt::format("--http=asio --unix-socket {}", SocketPath));
+
+ // Connect via Unix socket (BaseUri still needed for Host header)
+ HttpClientSettings Settings;
+ Settings.UnixSocketPath = SocketPath;
+ HttpClient Http{fmt::format("http://localhost:{}", PortNumber), Settings, {}};
+
+ SUBCASE("GET over unix socket")
+ {
+ HttpClient::Response Res = Http.Get("/testing/hello");
+ CHECK(Res.IsSuccess());
+ }
+
+ SUBCASE("POST echo over unix socket")
+ {
+ IoBuffer Body{IoBuffer::Wrap, "unix-test", 9};
+ HttpClient::Response Res = Http.Post("/testing/echo", Body);
+ CHECK(Res.IsSuccess());
+ CHECK(Res.ResponsePayload.GetView().EqualBytes(Body.GetView()));
+ }
+}
+# endif
+
TEST_SUITE_END();
# if 0