Skip to content

Commit c238181

Browse files
Implement a function which returns server access url
1 parent 2239a70 commit c238181

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

include/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace kiwix
6969
int getPort() const;
7070
IpAddress getAddress() const;
7171
IpMode getIpMode() const;
72+
std::vector<std::string> getServerAccessUrls() const;
7273

7374
protected:
7475
std::shared_ptr<Library> mp_library;

src/server.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@
2929

3030
namespace kiwix {
3131

32+
namespace
33+
{
34+
35+
std::string makeServerUrl(std::string host, int port, std::string root)
36+
{
37+
const int httpDefaultPort = 80;
38+
39+
if (port == httpDefaultPort) {
40+
return "http://" + host + root;
41+
} else {
42+
return "http://" + host + ":" + std::to_string(port) + root;
43+
}
44+
}
45+
46+
} // unnamed namespace
47+
3248
Server::Server(LibraryPtr library, std::shared_ptr<NameMapper> nameMapper) :
3349
mp_library(library),
3450
mp_nameMapper(nameMapper),
@@ -112,4 +128,16 @@ IpMode Server::getIpMode() const
112128
return mp_server->getIpMode();
113129
}
114130

131+
std::vector<std::string> Server::getServerAccessUrls() const
132+
{
133+
std::vector<std::string> result;
134+
if (!m_addr.addr.empty()) {
135+
result.push_back(makeServerUrl(m_addr.addr, m_port, m_root));
136+
}
137+
if (!m_addr.addr6.empty()) {
138+
result.push_back(makeServerUrl("[" + m_addr.addr6 + "]", m_port, m_root));
139+
}
140+
return result;
141+
}
142+
115143
}

0 commit comments

Comments
 (0)