drogon icon indicating copy to clipboard operation
drogon copied to clipboard

A way to get USE_SSL attribute from listener

Open paulocoutinhox opened this issue 2 years ago • 3 comments

Hi,

There is any way to know if a listener is using SSL? I can get the port and host, but not "use ssl" option from listener.

int32_t HttpServerImpl::getSocketPort()
{
    return drogon::app().getListeners()[0].toPort();
}

std::string HttpServerImpl::getSocketHost()
{
    return drogon::app().getListeners()[0].toIp();
}

Thanks.

paulocoutinhox avatar Jun 22 '22 17:06 paulocoutinhox

Sorry for the late reply. Why do you need access to a listener? You can query if a HTTP request is revived using req->isOnSecureConnection()

marty1885 avatar Jun 26 '22 08:06 marty1885

I only want show if the user can open the server in HTTP or HTTPS when i show the message on terminal.

https://github.com/nativium/nativium-http-server

paulocoutinhox avatar Jun 26 '22 14:06 paulocoutinhox

In that case you can modify addListener

void ListenerManager::addListener(...)
{
#ifndef OpenSSL_FOUND
    if (useSSL)
    {
        LOG_ERROR << "Can't use SSL without OpenSSL found in your system";
    }
#endif
    LOG_INFO << "Adding listener: " << ip << ":" << port << ", ssl: "
             << useSSL;
    listeners_.emplace_back(
        ip, port, useSSL, certFile, keyFile, useOldTLS, sslConfCmds);
}

Or TcpServer

void TcpServer::start()
{
    if(sslCtxPtr_)
        LOG_INFO << "SSL is enabled, listening on " << ipPort();

As of now there's API visible for programs to query this

marty1885 avatar Jun 27 '22 08:06 marty1885