aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/servers/httpsys.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-10-13 13:35:53 +0200
committerGitHub <[email protected]>2023-10-13 13:35:53 +0200
commite5930b287866b74323c8204ecdf88b44a83ceeae (patch)
treea6e49b1a8884774074b7c987e82fe7587ed335a4 /src/zenhttp/servers/httpsys.cpp
parentrestructured zenhttp (#472) (diff)
downloadzen-e5930b287866b74323c8204ecdf88b44a83ceeae.tar.xz
zen-e5930b287866b74323c8204ecdf88b44a83ceeae.zip
improved http.sys initialization diagnostics and amended logic for dedicated servers (#475)
Diffstat (limited to 'src/zenhttp/servers/httpsys.cpp')
-rw-r--r--src/zenhttp/servers/httpsys.cpp111
1 files changed, 71 insertions, 40 deletions
diff --git a/src/zenhttp/servers/httpsys.cpp b/src/zenhttp/servers/httpsys.cpp
index c1b4717cb..f1cd3e3fc 100644
--- a/src/zenhttp/servers/httpsys.cpp
+++ b/src/zenhttp/servers/httpsys.cpp
@@ -894,7 +894,7 @@ HttpAsyncWorkRequest::AsyncWorkItem::Execute()
*/
HttpSysServer::HttpSysServer(const HttpSysConfig& InConfig)
-: m_Log(logging::Get("http"))
+: m_Log(logging::Get("httpsys"))
, m_RequestLog(logging::Get("http_requests"))
, m_IsRequestLoggingEnabled(InConfig.IsRequestLoggingEnabled)
, m_IsAsyncResponseEnabled(InConfig.IsAsyncResponseEnabled)
@@ -1000,69 +1000,92 @@ HttpSysServer::InitializeServer(int BasePort)
return BasePort;
}
+ m_BaseUris.clear();
+
+ const bool AllowPortProbing = !m_InitialConfig.IsDedicatedServer;
+ const bool AllowLocalOnly = !m_InitialConfig.IsDedicatedServer;
+
int EffectivePort = BasePort;
Result = HttpAddUrlToUrlGroup(m_HttpUrlGroupId, WildcardUrlPath.c_str(), HTTP_URL_CONTEXT(0), 0);
- // Sharing violation implies the port is being used by another process
- for (int PortOffset = 1; (Result == ERROR_SHARING_VIOLATION) && (PortOffset < 10); ++PortOffset)
+ 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);
+ }
}
- m_BaseUris.clear();
if (Result == NO_ERROR)
{
m_BaseUris.push_back(WildcardUrlPath.c_str());
}
else if (Result == ERROR_ACCESS_DENIED)
{
- // If we can't register the wildcard path, we fall back to local paths
- // This local paths allow requests originating locally to function, but will not allow
- // remote origin requests to function. This can be remedied by using netsh
- // during an install process to grant permissions to route public access to the appropriate
- // port for the current user. eg:
- // netsh http add urlacl url=http://*:8558/ user=<some_user>
-
- ZEN_WARN("Unable to register handler using '{}' - falling back to local-only", WideToUtf8(WildcardUrlPath));
-
- const std::u8string_view Hosts[] = {u8"[::1]"sv, u8"localhost"sv, u8"127.0.0.1"sv};
-
- ULONG InternalResult = ERROR_SHARING_VIOLATION;
- for (int PortOffset = 0; (InternalResult == ERROR_SHARING_VIOLATION) && (PortOffset < 10); ++PortOffset)
+ if (AllowLocalOnly)
{
- EffectivePort = BasePort + (PortOffset * 100);
-
- for (const std::u8string_view Host : Hosts)
+ // If we can't register the wildcard path, we fall back to local paths
+ // This local paths allow requests originating locally to function, but will not allow
+ // remote origin requests to function. This can be remedied by using netsh
+ // during an install process to grant permissions to route public access to the appropriate
+ // port for the current user. eg:
+ // netsh http add urlacl url=http://*:8558/ user=<some_user>
+
+ ZEN_WARN(
+ "Unable to register handler using '{}' - falling back to local-only. "
+ "Please ensure the appropriate netsh URL reservation configuration "
+ "is made to allow http.sys access (see https://github.com/EpicGames/zen/blob/main/README.md)",
+ WideToUtf8(WildcardUrlPath));
+
+ const std::u8string_view Hosts[] = {u8"[::1]"sv, u8"localhost"sv, u8"127.0.0.1"sv};
+
+ ULONG InternalResult = ERROR_SHARING_VIOLATION;
+ for (int PortOffset = 0; (InternalResult == ERROR_SHARING_VIOLATION) && (PortOffset < 10); ++PortOffset)
{
- WideStringBuilder<64> LocalUrlPath;
- LocalUrlPath << u8"http://"sv << Host << u8":"sv << int64_t(EffectivePort) << u8"/"sv;
+ EffectivePort = BasePort + (PortOffset * 100);
- InternalResult = HttpAddUrlToUrlGroup(m_HttpUrlGroupId, LocalUrlPath.c_str(), HTTP_URL_CONTEXT(0), 0);
-
- if (InternalResult == NO_ERROR)
+ for (const std::u8string_view Host : Hosts)
{
- ZEN_INFO("Registered local handler '{}'", WideToUtf8(LocalUrlPath));
+ WideStringBuilder<64> LocalUrlPath;
+ LocalUrlPath << u8"http://"sv << Host << u8":"sv << int64_t(EffectivePort) << u8"/"sv;
- m_BaseUris.push_back(LocalUrlPath.c_str());
- }
- else
- {
- break;
+ InternalResult = HttpAddUrlToUrlGroup(m_HttpUrlGroupId, LocalUrlPath.c_str(), HTTP_URL_CONTEXT(0), 0);
+
+ if (InternalResult == NO_ERROR)
+ {
+ ZEN_WARN("Registered local-only handler '{}' - this is not accessible from remote hosts", WideToUtf8(LocalUrlPath));
+
+ m_BaseUris.push_back(LocalUrlPath.c_str());
+ }
+ else
+ {
+ break;
+ }
}
}
}
+ else
+ {
+ ZEN_ERROR(
+ "Unable to register URL handler for '{}' - access denied. Please ensure the appropriate netsh URL reservation "
+ "configuration is made to allow http.sys access (see https://github.com/EpicGames/zen/blob/main/README.md)",
+ WideToUtf8(WildcardUrlPath));
+
+ return 0;
+ }
}
if (m_BaseUris.empty())
{
ZEN_ERROR("Failed to add base URL to URL group for '{}': {:#x}", WideToUtf8(WildcardUrlPath), Result);
- return BasePort;
+ return 0;
}
HTTP_BINDING_INFO HttpBindingInfo = {{0}, 0};
@@ -1216,7 +1239,7 @@ HttpSysServer::Run(bool IsInteractive)
{
if (IsInteractive)
{
- zen::logging::ConsoleLog().info("Zen Server running. Press ESC or Q to quit");
+ zen::logging::ConsoleLog().info("Zen Server running (http.sys). Press ESC or Q to quit");
}
do
@@ -1986,9 +2009,16 @@ InitialRequestHandler::HandleCompletion(ULONG IoResult, ULONG_PTR NumberOfBytesT
int
HttpSysServer::Initialize(int BasePort)
{
- int EffectivePort = InitializeServer(BasePort);
- StartServer();
- return EffectivePort;
+ if (int EffectivePort = InitializeServer(BasePort))
+ {
+ StartServer();
+
+ return EffectivePort;
+ }
+
+ ZEN_WARN("http.sys server was not initialized");
+
+ return 0;
}
void
@@ -1996,6 +2026,7 @@ HttpSysServer::RequestExit()
{
m_ShutdownEvent.Set();
}
+
void
HttpSysServer::RegisterService(HttpService& Service)
{