From 26a70170fbd94f841fdf69f0e53c842f0501f859 Mon Sep 17 00:00:00 2001 From: redPanther Date: Tue, 16 Aug 2016 17:12:47 +0200 Subject: [PATCH] webserver fix (#181) fix default index.html in subfolders fix \r\n appended to data --- libsrc/webconfig/QtHttpClientWrapper.cpp | 2 +- libsrc/webconfig/StaticFileServing.cpp | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/libsrc/webconfig/QtHttpClientWrapper.cpp b/libsrc/webconfig/QtHttpClientWrapper.cpp index eb8cff5c..9ff08539 100644 --- a/libsrc/webconfig/QtHttpClientWrapper.cpp +++ b/libsrc/webconfig/QtHttpClientWrapper.cpp @@ -187,7 +187,7 @@ void QtHttpClientWrapper::onReplySendDataRequested (void) { QtHttpClientWrapper::ParsingStatus QtHttpClientWrapper::sendReplyToClient (QtHttpReply * reply) { if (reply != Q_NULLPTR) { if (!reply->useChunked ()) { - reply->appendRawData (CRLF); + //reply->appendRawData (CRLF); // send all headers and all data in one shot reply->requestSendHeaders (); reply->requestSendData (); diff --git a/libsrc/webconfig/StaticFileServing.cpp b/libsrc/webconfig/StaticFileServing.cpp index 4230b23e..341b0492 100644 --- a/libsrc/webconfig/StaticFileServing.cpp +++ b/libsrc/webconfig/StaticFileServing.cpp @@ -6,6 +6,7 @@ #include #include #include +#include StaticFileServing::StaticFileServing (Hyperion *hyperion, QString baseUrl, quint16 port, QObject * parent) : QObject (parent) @@ -74,13 +75,24 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl } return; } - - // get static files - if ( path == "/" || path.isEmpty() || ! QFile::exists(_baseUrl % "/" % path) ) - path = "index.html"; - QFile file (_baseUrl % "/" % path); - if (file.exists ()) + QFileInfo info(_baseUrl % "/" % path); + if ( path == "/" || path.isEmpty() || ! info.exists() ) + { + path = "index.html"; + } + else if (info.isDir() && path.endsWith("/") ) + { + path += "index.html"; + } + else if (info.isDir() && ! path.endsWith("/") ) + { + path += "/index.html"; + } + + // get static files + QFile file(_baseUrl % "/" % path); + if (file.exists()) { QMimeType mime = _mimeDb->mimeTypeForFile (file.fileName ()); if (file.open (QFile::ReadOnly)) {