File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,8 @@ namespace kiwix
6969 int getPort () const ;
7070 IpAddress getAddress () const ;
7171 IpMode getIpMode () const ;
72+ std::string getDisplayableAddress ();
73+ std::string getDisplayableAddress6 ();
7274
7375 protected:
7476 std::shared_ptr<Library> mp_library;
Original file line number Diff line number Diff line change @@ -106,4 +106,43 @@ IpMode Server::getIpMode() const
106106 return mp_server->getIpMode ();
107107}
108108
109+ std::string Server::getDisplayableAddress ()
110+ {
111+ kiwix::IpAddress addresses = Server::getAddress ();
112+ if (addresses.addr .empty ()) return getDisplayableAddress6 (); // as a fallback return ipv6 address as one of them has to be set
113+
114+ std::string result = " http://" ;
115+ std::string suffix;
116+
117+ if (Server::getPort ()==80 )
118+ {
119+ suffix = mp_server->getRootPrefixOfDecodedURL ();
120+ }else
121+ {
122+ suffix = " :" + std::to_string (Server::getPort ()) + mp_server->getRootPrefixOfDecodedURL ();
123+ }
124+
125+ result = result + addresses.addr + suffix;
126+ return result;
127+ }
128+
129+ std::string Server::getDisplayableAddress6 ()
130+ {
131+ kiwix::IpAddress addresses = Server::getAddress ();
132+ if (addresses.addr6 .empty ()) return getDisplayableAddress (); // as a fallback return ipv4 address as one of them has to be set
133+
134+ std::string result = " http://" ;
135+ std::string suffix;
136+
137+ if (Server::getPort ()==80 )
138+ {
139+ suffix = mp_server->getRootPrefixOfDecodedURL ();
140+ }else
141+ {
142+ suffix = " :" + std::to_string (Server::getPort ()) + mp_server->getRootPrefixOfDecodedURL ();
143+ }
144+
145+ result = result + " [" + addresses.addr6 + " ]" + suffix;
146+ return result;
109147}
148+ }
Original file line number Diff line number Diff line change @@ -124,6 +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+ std::string getRootPrefixOfDecodedURL () const { return m_rootPrefixOfDecodedURL; }
127128
128129 private: // functions
129130 std::unique_ptr<Response> handle_request (const RequestContext& request);
You can’t perform that action at this time.
0 commit comments