diff --git a/include/QHttpEngine/qhttpserver.h b/include/QHttpEngine/qhttpserver.h index 9d2d2ac..e9856f3 100644 --- a/include/QHttpEngine/qhttpserver.h +++ b/include/QHttpEngine/qhttpserver.h @@ -30,8 +30,7 @@ #include "qhttpengine_global.h" #if !defined(QT_NO_SSL) -class QSslCertificate; -class QSslKey; +class QSslConfiguration; #endif class QHttpHandler; @@ -85,14 +84,12 @@ public: #if !defined(QT_NO_SSL) /** - * @brief Set the certificate to use for TLS + * @brief Set the SSL configuration for the server + * + * If the configuration is not NULL, the server will begin negotiating + * connections using SSL/TLS. */ - void setCertificate(const QSslCertificate &certificate); - - /** - * @brief Set the private key to use for TLS - */ - void setPrivateKey(const QSslKey &key); + void setSslConfiguration(const QSslConfiguration &configuration); #endif protected: diff --git a/src/qhttpserver.cpp b/src/qhttpserver.cpp index 5ed1577..29505f8 100644 --- a/src/qhttpserver.cpp +++ b/src/qhttpserver.cpp @@ -72,14 +72,9 @@ void QHttpServer::setHandler(QHttpHandler *handler) } #if !defined(QT_NO_SSL) -void QHttpServer::setCertificate(const QSslCertificate &certificate) +void QHttpServer::setSslConfiguration(const QSslConfiguration &configuration) { - d->configuration.setLocalCertificate(certificate); -} - -void QHttpServer::setPrivateKey(const QSslKey &key) -{ - d->configuration.setPrivateKey(key); + d->configuration = configuration; } #endif @@ -89,22 +84,25 @@ void QHttpServer::incomingConnection(qintptr socketDescriptor) if (!d->configuration.isNull()) { // Initialize the socket with the SSL configuration - QSslSocket *sslSocket = new QSslSocket(this); + QSslSocket *socket = new QSslSocket(this); // Wait until encryption is complete before processing the socket - connect(sslSocket, &QSslSocket::encrypted, [this, sslSocket]() { - d->process(sslSocket); + connect(socket, &QSslSocket::encrypted, [this, socket]() { + d->process(socket); }); - sslSocket->setSocketDescriptor(socketDescriptor); - sslSocket->setSslConfiguration(d->configuration); - sslSocket->startServerEncryption(); + socket->setSocketDescriptor(socketDescriptor); + socket->setSslConfiguration(d->configuration); + socket->startServerEncryption(); } else { #endif + QTcpSocket *socket = new QTcpSocket(this); + socket->setSocketDescriptor(socketDescriptor); + // Process the socket immediately - d->process(new QTcpSocket(this)); + d->process(socket); #if !defined(QT_NO_SSL) }