Skip to content

Commit c5f1326

Browse files
Normalize m_root in Server itself
1 parent 1cb2fb8 commit c5f1326

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

src/server.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ void Server::stop() {
7575
void Server::setRoot(const std::string& root)
7676
{
7777
m_root = root;
78-
if (m_root[0] != '/') {
79-
m_root = "/" + m_root;
80-
}
81-
if (m_root.back() == '/') {
82-
m_root.erase(m_root.size() - 1);
83-
}
78+
while (!m_root.empty() && m_root.back() == '/')
79+
m_root.pop_back();
80+
81+
while (!m_root.empty() && m_root.front() == '/')
82+
m_root = m_root.substr(1);
83+
m_root = m_root.empty() ? m_root : "/" + m_root;
8484
}
8585

8686
void Server::setAddress(const std::string& addr)

src/server/internalServer.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,6 @@ bool ipAvailable(const std::string addr)
100100
return false;
101101
}
102102

103-
inline std::string normalizeRootUrl(std::string rootUrl)
104-
{
105-
while ( !rootUrl.empty() && rootUrl.back() == '/' )
106-
rootUrl.pop_back();
107-
108-
while ( !rootUrl.empty() && rootUrl.front() == '/' )
109-
rootUrl = rootUrl.substr(1);
110-
return rootUrl.empty() ? rootUrl : "/" + rootUrl;
111-
}
112-
113103
std::string
114104
fullURL2LocalURL(const std::string& fullUrl, const std::string& rootLocation)
115105
{
@@ -444,7 +434,7 @@ InternalServer::InternalServer(LibraryPtr library,
444434
std::string contentServerUrl) :
445435
m_addr(addr),
446436
m_port(port),
447-
m_root(normalizeRootUrl(root)),
437+
m_root(root),
448438
m_rootPrefixOfDecodedURL(m_root),
449439
m_nbThreads(nbThreads),
450440
m_multizimSearchLimit(multizimSearchLimit),

0 commit comments

Comments
 (0)