Skip to content

Commit ea9f93d

Browse files
Add functions which return displayable addresses
stuf ?? st
1 parent dd09e3c commit ea9f93d

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,33 @@ IpMode Server::getIpMode() const
106106
return mp_server->getIpMode();
107107
}
108108

109+
std::vector<std::string> Server::getServerAccessUrls() const
110+
{
111+
std::vector<std::string> result;
112+
const kiwix::IpAddress addresses = m_addr;
113+
const int port = m_port;
114+
const std::string root = m_root;
115+
if (!addresses.addr.empty()) {
116+
result.push_back(makeServerUrl(addresses.addr, port, root));
117+
}
118+
if (!addresses.addr6.empty()) {
119+
result.push_back(makeServerUrl("[" + addresses.addr6 + "]", port, root));
120+
}
121+
return result;
122+
}
123+
124+
namespace
125+
{
126+
std::string makeServerUrl(std::string host, int port, std::string root)
127+
{
128+
int httpDefaultPort = 80;
129+
130+
if (port == httpDefaultPort) {
131+
return "http://" + host + root;
132+
} else {
133+
return "http://" + host + ":" + std::to_string(port) + root;
134+
}
135+
}
136+
} // namespace
109137
}
138+

src/server/internalServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class InternalServer {
124124
IpAddress getAddress() const { return m_addr; }
125125
int getPort() const { return m_port; }
126126
IpMode getIpMode() const { return m_ipMode; }
127-
127+
128128
private: // functions
129129
std::unique_ptr<Response> handle_request(const RequestContext& request);
130130
std::unique_ptr<Response> build_redirect(const std::string& bookName, const zim::Item& item) const;

0 commit comments

Comments
 (0)