# HG changeset patch # User Sebastien Jodogne # Date 1751898611 -7200 # Node ID faf965a59f5cda4de2a6f7b74e82068d482889c1 # Parent add00150107b0f936c73b7e959bc23cfa577d6b4 added HttpServer::SetRedirectForbiddenToRoot() diff -r add00150107b -r faf965a59f5c OrthancFramework/Sources/HttpServer/HttpServer.cpp --- a/OrthancFramework/Sources/HttpServer/HttpServer.cpp Fri Jul 04 15:33:46 2025 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpServer.cpp Mon Jul 07 16:30:11 2025 +0200 @@ -1203,15 +1203,6 @@ AccessMode accessMode = IsAccessGranted(server, headers); - // Authenticate this connection - if (server.IsAuthenticationEnabled() && - accessMode == AccessMode_Forbidden) - { - output.SendUnauthorized(server.GetRealm()); // 401 error - return; - } - - #if ORTHANC_ENABLE_MONGOOSE == 1 // Apply the filter, if it is installed char remoteIp[24]; @@ -1248,6 +1239,41 @@ } + // Authenticate this connection + if (server.IsAuthenticationEnabled() && + accessMode == AccessMode_Forbidden) + { + if (server.IsRedirectForbiddenToRoot() && + uri.size() > 0) + { + // This is new in Orthanc 1.12.9 + std::string redirectionToRoot; + + std::string tmp(requestUri); + if (tmp.back() == '/') + { + redirectionToRoot = "../"; + } + else + { + redirectionToRoot = "./"; + } + + for (size_t i = 0; i < uri.size() - 1; i++) + { + redirectionToRoot += "../"; + } + + output.Redirect(redirectionToRoot); + } + else + { + output.SendUnauthorized(server.GetRealm()); // 401 error + } + return; + } + + // Compute the HTTP method, taking method faking into consideration method = HttpMethod_Get; @@ -2204,4 +2230,17 @@ } } #endif + + + bool HttpServer::IsRedirectForbiddenToRoot() const + { + return redirectForbiddenToRoot_; + } + + + void HttpServer::SetRedirectForbiddenToRoot(bool redirect) + { + Stop(); + redirectForbiddenToRoot_ = redirect; + } } diff -r add00150107b -r faf965a59f5c OrthancFramework/Sources/HttpServer/HttpServer.h --- a/OrthancFramework/Sources/HttpServer/HttpServer.h Fri Jul 04 15:33:46 2025 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpServer.h Mon Jul 07 16:30:11 2025 +0200 @@ -114,6 +114,7 @@ unsigned int threadsCount_; bool tcpNoDelay_; unsigned int requestTimeout_; // In seconds + bool redirectForbiddenToRoot_; // New in Orthanc 1.12.9 #if ORTHANC_ENABLE_PUGIXML == 1 WebDavBuckets webDavBuckets_; @@ -226,5 +227,9 @@ const std::map& headers, const std::string& body, const std::string& boundary); + + bool IsRedirectForbiddenToRoot() const; + + void SetRedirectForbiddenToRoot(bool redirect); }; }