diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index e1017e287..a9d809e39 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -94,6 +94,22 @@ inline std::string normalizeRootUrl(std::string rootUrl) return rootUrl.empty() ? rootUrl : "/" + rootUrl; } +std::string +fullURL2LocalURL(const std::string& full_url, const std::string& rootLocation) +{ + if (rootLocation.empty()) { + // nothing special to handle. + return full_url; + } else if (full_url == rootLocation) { + return "/"; + } else if (full_url.size() > rootLocation.size() && + full_url.substr(0, rootLocation.size()+1) == rootLocation + "/") { + return full_url.substr(rootLocation.size()); + } else { + return ""; + } +} + Filter get_search_filter(const RequestContext& request, const std::string& prefix="") { auto filter = kiwix::Filter().valid(true).local(true); @@ -494,7 +510,7 @@ static MHD_Result staticHandlerCallback(void* cls, } MHD_Result InternalServer::handlerCallback(struct MHD_Connection* connection, - const char* url, + const char* fullUrl, const char* method, const char* version, const char* upload_data, @@ -505,8 +521,10 @@ MHD_Result InternalServer::handlerCallback(struct MHD_Connection* connection, if (m_verbose.load() ) { printf("======================\n"); printf("Requesting : \n"); - printf("full_url : %s\n", url); + printf("full_url : %s\n", fullUrl); } + + const auto url = fullURL2LocalURL(fullUrl, m_root); RequestContext request(connection, m_root, url, method, version); if (m_verbose.load() ) { @@ -527,7 +545,7 @@ MHD_Result InternalServer::handlerCallback(struct MHD_Connection* connection, printf("========== INTERNAL ERROR !! ============\n"); if (!m_verbose.load()) { printf("Requesting : \n"); - printf("full_url : %s\n", url); + printf("full_url : %s\n", fullUrl); request.print_debug_info(); } } diff --git a/src/server/request_context.cpp b/src/server/request_context.cpp index d418d75af..4002671fc 100644 --- a/src/server/request_context.cpp +++ b/src/server/request_context.cpp @@ -49,32 +49,16 @@ RequestMethod str2RequestMethod(const std::string& method) { else return RequestMethod::OTHER; } -std::string -fullURL2LocalURL(const std::string& full_url, const std::string& rootLocation) -{ - if (rootLocation.empty()) { - // nothing special to handle. - return full_url; - } else if (full_url == rootLocation) { - return "/"; - } else if (full_url.size() > rootLocation.size() && - full_url.substr(0, rootLocation.size()+1) == rootLocation + "/") { - return full_url.substr(rootLocation.size()); - } else { - return ""; - } -} - } // unnamed namespace RequestContext::RequestContext(struct MHD_Connection* connection, - std::string _rootLocation, - const std::string& _url, + const std::string& _rootLocation, + const std::string& unrootedUrl, const std::string& _method, const std::string& version) : rootLocation(_rootLocation), - full_url(_url), - url(fullURL2LocalURL(_url, _rootLocation)), + full_url(_rootLocation + unrootedUrl), + url(unrootedUrl), method(str2RequestMethod(_method)), version(version), requestIndex(s_requestIndex++), diff --git a/src/server/request_context.h b/src/server/request_context.h index 9017a6b28..bea0ff804 100644 --- a/src/server/request_context.h +++ b/src/server/request_context.h @@ -57,8 +57,8 @@ class IndexError: public std::runtime_error {}; class RequestContext { public: // functions RequestContext(struct MHD_Connection* connection, - std::string rootLocation, - const std::string& url, + const std::string& rootLocation, + const std::string& unrootedUrl, const std::string& method, const std::string& version); ~RequestContext();