Mercurial > hg > orthanc
changeset 6219:faf965a59f5c
added HttpServer::SetRedirectForbiddenToRoot()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 Jul 2025 16:30:11 +0200 |
parents | add00150107b |
children | 49991d8aef82 |
files | OrthancFramework/Sources/HttpServer/HttpServer.cpp OrthancFramework/Sources/HttpServer/HttpServer.h |
diffstat | 2 files changed, 53 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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; + } }
--- 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<std::string, std::string>& headers, const std::string& body, const std::string& boundary); + + bool IsRedirectForbiddenToRoot() const; + + void SetRedirectForbiddenToRoot(bool redirect); }; }