From 442de30ff716ec16cdb9fb18093c03961a5ef68d Mon Sep 17 00:00:00 2001 From: renaud gaudin Date: Thu, 28 Jul 2022 15:51:46 +0000 Subject: [PATCH] Normalize printed rootLocation Reusing libkiwix's normalizeRootUrl() to display a more reliable representation of the rootLocation the InternalServer will be using. Can't reuse server.m_root as it is private. --- src/server/kiwix-serve.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 4dd091c..1b8e2ad 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -103,6 +103,16 @@ std::string loadCustomTemplate (std::string customIndexPath) { return indexTemplateString; } +inline std::string normalizeRootUrl(std::string rootUrl) +{ + while ( !rootUrl.empty() && rootUrl.back() == '/' ) + rootUrl.pop_back(); + + while ( !rootUrl.empty() && rootUrl.front() == '/' ) + rootUrl = rootUrl.substr(1); + return rootUrl.empty() ? rootUrl : "/" + rootUrl; +} + volatile sig_atomic_t waiting = false; volatile sig_atomic_t libraryMustBeReloaded = false; @@ -393,7 +403,7 @@ int main(int argc, char** argv) exit(1); } - std::string url = "http://" + server.getAddress() + ":" + std::to_string(server.getPort()) + rootLocation; + std::string url = "http://" + server.getAddress() + ":" + std::to_string(server.getPort()) + normalizeRootUrl(rootLocation); std::cout << "The Kiwix server is running and can be accessed in the local network at: " << url << std::endl;