diff options
| author | Stefan Boberg <[email protected]> | 2026-03-12 17:02:01 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-03-12 17:02:01 +0100 |
| commit | 3aa6aa83d05249d7081a8c19a28ce9b9c4566da2 (patch) | |
| tree | f4f14006e82cdf0ed05083c9af90e17116614368 /src/zenhttp | |
| parent | Update CHANGELOG.md (diff) | |
| download | zen-3aa6aa83d05249d7081a8c19a28ce9b9c4566da2.tar.xz zen-3aa6aa83d05249d7081a8c19a28ce9b9c4566da2.zip | |
Add --no-network option (#831)
- Add `--no-network` CLI option which disables all TCP/HTTPS listeners, restricting zenserver to Unix domain socket communication only.
- Also fixes asio upgrade breakage on main
Diffstat (limited to 'src/zenhttp')
| -rw-r--r-- | src/zenhttp/httpserver.cpp | 2 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpserver.h | 9 | ||||
| -rw-r--r-- | src/zenhttp/servers/httpasio.cpp | 35 | ||||
| -rw-r--r-- | src/zenhttp/servers/httpasio.h | 1 |
4 files changed, 29 insertions, 18 deletions
diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp index 1a0018908..6ba0ca563 100644 --- a/src/zenhttp/httpserver.cpp +++ b/src/zenhttp/httpserver.cpp @@ -1157,7 +1157,7 @@ CreateHttpServerClass(const std::string_view ServerClass, const HttpServerConfig ZEN_INFO("using asio HTTP server implementation") return CreateHttpAsioServer(AsioConfig { .ThreadCount = Config.ThreadCount, .ForceLoopback = Config.ForceLoopback, .IsDedicatedServer = Config.IsDedicatedServer, - .UnixSocketPath = Config.UnixSocketPath, + .NoNetwork = Config.NoNetwork, .UnixSocketPath = Config.UnixSocketPath, #if ZEN_USE_OPENSSL .HttpsPort = Config.HttpsPort, .CertFile = Config.CertFile, .KeyFile = Config.KeyFile, #endif diff --git a/src/zenhttp/include/zenhttp/httpserver.h b/src/zenhttp/include/zenhttp/httpserver.h index d98877d16..627e7921f 100644 --- a/src/zenhttp/include/zenhttp/httpserver.h +++ b/src/zenhttp/include/zenhttp/httpserver.h @@ -329,10 +329,11 @@ struct HttpServerConfig std::vector<HttpServerPluginConfig> PluginConfigs; bool ForceLoopback = false; unsigned int ThreadCount = 0; - std::string UnixSocketPath; // Unix domain socket path (empty = disabled, non-Windows only) - int HttpsPort = 0; // HTTPS listen port (0 = disabled, ASIO backend) - std::string CertFile; // PEM certificate chain file path - std::string KeyFile; // PEM private key file path + std::string UnixSocketPath; // Unix domain socket path (empty = disabled, non-Windows only) + bool NoNetwork = false; // Disable TCP/HTTPS listeners; only accept connections via UnixSocketPath + int HttpsPort = 0; // HTTPS listen port (0 = disabled, ASIO backend) + std::string CertFile; // PEM certificate chain file path + std::string KeyFile; // PEM private key file path struct { diff --git a/src/zenhttp/servers/httpasio.cpp b/src/zenhttp/servers/httpasio.cpp index e8b27da70..643f33618 100644 --- a/src/zenhttp/servers/httpasio.cpp +++ b/src/zenhttp/servers/httpasio.cpp @@ -2157,15 +2157,18 @@ HttpAsioServerImpl::Start(uint16_t Port, const AsioConfig& Config) ZEN_INFO("starting asio http with {} service threads", Config.ThreadCount); - m_Acceptor.reset( - new asio_http::HttpAcceptor(*this, m_IoService, Port, Config.ForceLoopback, /*AllowPortProbing */ !Config.IsDedicatedServer)); - - if (!m_Acceptor->IsValid()) + if (!Config.NoNetwork) { - return 0; - } + m_Acceptor.reset( + new asio_http::HttpAcceptor(*this, m_IoService, Port, Config.ForceLoopback, /*AllowPortProbing */ !Config.IsDedicatedServer)); + + if (!m_Acceptor->IsValid()) + { + return 0; + } - m_Acceptor->Start(); + m_Acceptor->Start(); + } #if defined(ASIO_HAS_LOCAL_SOCKETS) if (!Config.UnixSocketPath.empty()) @@ -2184,7 +2187,7 @@ HttpAsioServerImpl::Start(uint16_t Port, const AsioConfig& Config) #endif #if ZEN_USE_OPENSSL - if (!Config.CertFile.empty() && !Config.KeyFile.empty()) + if (!Config.NoNetwork && !Config.CertFile.empty() && !Config.KeyFile.empty()) { m_SslContext = std::make_unique<asio::ssl::context>(asio::ssl::context::tlsv12_server); m_SslContext->set_options(asio::ssl::context::default_workarounds | asio::ssl::context::no_sslv2 | asio::ssl::context::no_sslv3 | @@ -2243,12 +2246,18 @@ HttpAsioServerImpl::Start(uint16_t Port, const AsioConfig& Config) }); } - ZEN_INFO("asio http started in {} mode, using {} threads on port {}", - Config.IsDedicatedServer ? "DEDICATED" : "NORMAL", - Config.ThreadCount, - m_Acceptor->GetAcceptPort()); + if (m_Acceptor) + { + ZEN_INFO("asio http started in {} mode, using {} threads on port {}", + Config.IsDedicatedServer ? "DEDICATED" : "NORMAL", + Config.ThreadCount, + m_Acceptor->GetAcceptPort()); + + return m_Acceptor->GetAcceptPort(); + } - return m_Acceptor->GetAcceptPort(); + ZEN_INFO("asio http started in no-network mode, using {} threads (unix socket only)", Config.ThreadCount); + return Port; } void diff --git a/src/zenhttp/servers/httpasio.h b/src/zenhttp/servers/httpasio.h index 5adf4d5e8..21d10170e 100644 --- a/src/zenhttp/servers/httpasio.h +++ b/src/zenhttp/servers/httpasio.h @@ -11,6 +11,7 @@ struct AsioConfig unsigned int ThreadCount = 0; bool ForceLoopback = false; bool IsDedicatedServer = false; + bool NoNetwork = false; std::string UnixSocketPath; #if ZEN_USE_OPENSSL int HttpsPort = 0; // 0 = auto-assign; set CertFile/KeyFile to enable HTTPS |