Normalize m_root in Server itself

This commit is contained in:
Vighnesh
2025-10-30 23:27:14 +05:30
parent cffca3ad85
commit c2df0a99fe
2 changed files with 7 additions and 17 deletions

View File

@@ -75,12 +75,12 @@ void Server::stop() {
void Server::setRoot(const std::string& root)
{
m_root = root;
if (m_root[0] != '/') {
m_root = "/" + m_root;
}
if (m_root.back() == '/') {
m_root.erase(m_root.size() - 1);
}
while (!m_root.empty() && m_root.back() == '/')
m_root.pop_back();
while (!m_root.empty() && m_root.front() == '/')
m_root = m_root.substr(1);
m_root = m_root.empty() ? m_root : "/" + m_root;
}
void Server::setAddress(const std::string& addr)

View File

@@ -99,16 +99,6 @@ bool ipAvailable(const std::string addr)
return false;
}
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;
}
std::string
fullURL2LocalURL(const std::string& fullUrl, const std::string& rootLocation)
{
@@ -440,7 +430,7 @@ InternalServer::InternalServer(LibraryPtr library,
std::string contentServerUrl) :
m_addr(addr),
m_port(port),
m_root(normalizeRootUrl(root)),
m_root(root),
m_rootPrefixOfDecodedURL(m_root),
m_nbThreads(nbThreads),
m_multizimSearchLimit(multizimSearchLimit),