Merge PR #338: Fix the webserver for serving static files
This commit is contained in:
commit
49e4c1caae
@ -264,7 +264,7 @@ void ServerManager::webServerConfigurationChanged(const QString &id)
|
|||||||
qDebug(dcServerManager()) << "Restarting Web server for" << config.address << config.port << "SSL" << (config.sslEnabled ? "enabled" : "disabled") << "Authentication" << (config.authenticationEnabled ? "enabled" : "disabled");
|
qDebug(dcServerManager()) << "Restarting Web server for" << config.address << config.port << "SSL" << (config.sslEnabled ? "enabled" : "disabled") << "Authentication" << (config.authenticationEnabled ? "enabled" : "disabled");
|
||||||
unregisterZeroConfService(id, "http");
|
unregisterZeroConfService(id, "http");
|
||||||
server->stopServer();
|
server->stopServer();
|
||||||
server->reconfigureServer(config);
|
server->setConfiguration(config);
|
||||||
} else {
|
} else {
|
||||||
qDebug(dcServerManager()) << "Received a Web Server config change event but don't have a Web Server instance for it. Creating new WebServer instance on" << config.address.toString() << config.port << "(SSL:" << config.sslEnabled << ")";
|
qDebug(dcServerManager()) << "Received a Web Server config change event but don't have a Web Server instance for it. Creating new WebServer instance on" << config.address.toString() << config.port << "(SSL:" << config.sslEnabled << ")";
|
||||||
server = new WebServer(config, m_sslConfiguration, this);
|
server = new WebServer(config, m_sslConfiguration, this);
|
||||||
|
|||||||
@ -163,22 +163,6 @@ void TcpServer::onDataAvailable(QSslSocket * socket, const QByteArray &data)
|
|||||||
emit dataAvailable(clientId, data);
|
emit dataAvailable(clientId, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! Returns true if this \l{TcpServer} could be reconfigured with the given \a config. */
|
|
||||||
void TcpServer::reconfigureServer(const ServerConfiguration &config)
|
|
||||||
{
|
|
||||||
if (configuration().address == config.address &&
|
|
||||||
configuration().port == config.port &&
|
|
||||||
configuration().sslEnabled == config.sslEnabled &&
|
|
||||||
configuration().authenticationEnabled == config.authenticationEnabled &&
|
|
||||||
m_server->isListening())
|
|
||||||
return;
|
|
||||||
|
|
||||||
stopServer();
|
|
||||||
setConfiguration(config);
|
|
||||||
startServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Sets the name of this server to the given \a serverName. */
|
/*! Sets the name of this server to the given \a serverName. */
|
||||||
void TcpServer::setServerName(const QString &serverName)
|
void TcpServer::setServerName(const QString &serverName)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -104,7 +104,6 @@ private slots:
|
|||||||
void onError(QAbstractSocket::SocketError error);
|
void onError(QAbstractSocket::SocketError error);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void reconfigureServer(const ServerConfiguration &configuration);
|
|
||||||
void setServerName(const QString &serverName) override;
|
void setServerName(const QString &serverName) override;
|
||||||
bool startServer() override;
|
bool startServer() override;
|
||||||
bool stopServer() override;
|
bool stopServer() override;
|
||||||
|
|||||||
@ -433,7 +433,7 @@ void WebServer::readClient()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
if (file.open(QFile::ReadOnly | QFile::Truncate)) {
|
if (file.open(QFile::ReadOnly)) {
|
||||||
qCDebug(dcWebServer()) << "Load file" << file.fileName();
|
qCDebug(dcWebServer()) << "Load file" << file.fileName();
|
||||||
HttpReply *reply = HttpReply::createSuccessReply();
|
HttpReply *reply = HttpReply::createSuccessReply();
|
||||||
|
|
||||||
@ -487,7 +487,6 @@ void WebServer::onDisconnected()
|
|||||||
if (client->address() == socket->peerAddress()) {
|
if (client->address() == socket->peerAddress()) {
|
||||||
client->removeConnection(socket);
|
client->removeConnection(socket);
|
||||||
if (client->connections().isEmpty()) {
|
if (client->connections().isEmpty()) {
|
||||||
qCDebug(dcWebServer()) << "Delete client" << client->address().toString();
|
|
||||||
m_webServerClients.removeAll(client);
|
m_webServerClients.removeAll(client);
|
||||||
client->deleteLater();
|
client->deleteLater();
|
||||||
}
|
}
|
||||||
@ -549,19 +548,9 @@ void WebServer::onAsyncReplyFinished()
|
|||||||
*
|
*
|
||||||
* \sa WebServerConfiguration
|
* \sa WebServerConfiguration
|
||||||
*/
|
*/
|
||||||
void WebServer::reconfigureServer(const WebServerConfiguration &config)
|
void WebServer::setConfiguration(const WebServerConfiguration &config)
|
||||||
{
|
{
|
||||||
if (m_configuration.address == config.address &&
|
|
||||||
m_configuration.port == config.port &&
|
|
||||||
m_configuration.sslEnabled == config.sslEnabled &&
|
|
||||||
m_configuration.authenticationEnabled == config.authenticationEnabled &&
|
|
||||||
m_configuration.publicFolder == config.publicFolder &&
|
|
||||||
isListening())
|
|
||||||
return;
|
|
||||||
|
|
||||||
stopServer();
|
|
||||||
m_configuration = config;
|
m_configuration = config;
|
||||||
startServer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Sets the server name to the given \a serverName. */
|
/*! Sets the server name to the given \a serverName. */
|
||||||
|
|||||||
@ -123,7 +123,7 @@ private slots:
|
|||||||
void onAsyncReplyFinished();
|
void onAsyncReplyFinished();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void reconfigureServer(const WebServerConfiguration &config);
|
void setConfiguration(const WebServerConfiguration &config);
|
||||||
void setServerName(const QString &serverName);
|
void setServerName(const QString &serverName);
|
||||||
bool startServer();
|
bool startServer();
|
||||||
bool stopServer();
|
bool stopServer();
|
||||||
|
|||||||
@ -197,25 +197,6 @@ void WebSocketServer::onPing(quint64 elapsedTime, const QByteArray &payload)
|
|||||||
qCDebug(dcWebSocketServer) << "Ping response from" << clientId.toString() << elapsedTime << payload;
|
qCDebug(dcWebSocketServer) << "Ping response from" << clientId.toString() << elapsedTime << payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! Returns true if this \l{WebSocketServer} could be reconfigured with the given \a config. */
|
|
||||||
void WebSocketServer::reconfigureServer(const ServerConfiguration &config)
|
|
||||||
{
|
|
||||||
if (configuration() == config && m_server->isListening()) {
|
|
||||||
qCDebug(dcWebSocketServer()) << "Configuration unchanged. Not restarting the server.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
stopServer();
|
|
||||||
qCDebug(dcWebSocketServer()) << "Stopped server for reconfiguration.";
|
|
||||||
|
|
||||||
setConfiguration(config);
|
|
||||||
|
|
||||||
// Start server with new configuration
|
|
||||||
qCDebug(dcWebSocketServer()) << "Restart server with new configuration.";
|
|
||||||
startServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Sets the server name to the given \a serverName. */
|
/*! Sets the server name to the given \a serverName. */
|
||||||
void WebSocketServer::setServerName(const QString &serverName)
|
void WebSocketServer::setServerName(const QString &serverName)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -77,7 +77,6 @@ private slots:
|
|||||||
void onPing(quint64 elapsedTime, const QByteArray & payload);
|
void onPing(quint64 elapsedTime, const QByteArray & payload);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void reconfigureServer(const ServerConfiguration &config);
|
|
||||||
void setServerName(const QString &serverName) override;
|
void setServerName(const QString &serverName) override;
|
||||||
bool startServer() override;
|
bool startServer() override;
|
||||||
bool stopServer() override;
|
bool stopServer() override;
|
||||||
|
|||||||
Reference in New Issue
Block a user