From c289d408765fe47d54987bd49fcf277f2419104a Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Thu, 9 Nov 2023 20:50:46 +0100 Subject: option for zenserver - `--http-forceloopback` (#516) * New option for zenserver - `--http-forceloopback` which forces opening of the server http server using loopback (local) connection (UE-199776) * add fallback to local connection for asio if we get access denied on public port --- src/zenhttp/servers/httpsys.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/zenhttp/servers/httpsys.cpp') diff --git a/src/zenhttp/servers/httpsys.cpp b/src/zenhttp/servers/httpsys.cpp index 4eeab6662..0b11d396b 100644 --- a/src/zenhttp/servers/httpsys.cpp +++ b/src/zenhttp/servers/httpsys.cpp @@ -1003,18 +1003,27 @@ HttpSysServer::InitializeServer(int BasePort) int EffectivePort = BasePort; - Result = HttpAddUrlToUrlGroup(m_HttpUrlGroupId, WildcardUrlPath.c_str(), HTTP_URL_CONTEXT(0), 0); - - if ((Result == ERROR_SHARING_VIOLATION) && AllowPortProbing) + if (m_InitialConfig.ForceLoopback) + { + // Force trigger of opening using local port + ZEN_ASSERT(AllowLocalOnly); + Result = ERROR_ACCESS_DENIED; + } + else { - // Sharing violation implies the port is being used by another process - for (int PortOffset = 1; (Result == ERROR_SHARING_VIOLATION) && (PortOffset < 10); ++PortOffset) + Result = HttpAddUrlToUrlGroup(m_HttpUrlGroupId, WildcardUrlPath.c_str(), HTTP_URL_CONTEXT(0), 0); + + if ((Result == ERROR_SHARING_VIOLATION) && AllowPortProbing) { - EffectivePort = BasePort + (PortOffset * 100); - WildcardUrlPath.Reset(); - WildcardUrlPath << u8"http://*:"sv << int64_t(EffectivePort) << u8"/"sv; + // Sharing violation implies the port is being used by another process + for (int PortOffset = 1; (Result == ERROR_SHARING_VIOLATION) && (PortOffset < 10); ++PortOffset) + { + EffectivePort = BasePort + (PortOffset * 100); + WildcardUrlPath.Reset(); + WildcardUrlPath << u8"http://*:"sv << int64_t(EffectivePort) << u8"/"sv; - Result = HttpAddUrlToUrlGroup(m_HttpUrlGroupId, WildcardUrlPath.c_str(), HTTP_URL_CONTEXT(0), 0); + Result = HttpAddUrlToUrlGroup(m_HttpUrlGroupId, WildcardUrlPath.c_str(), HTTP_URL_CONTEXT(0), 0); + } } } -- cgit v1.2.3