webserver fix (#181)

fix default index.html in subfolders
fix \r\n appended to data
This commit is contained in:
redPanther 2016-08-16 17:12:47 +02:00 committed by GitHub
parent c00edfb658
commit 26a70170fb
2 changed files with 19 additions and 7 deletions

View File

@ -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 ();

View File

@ -6,6 +6,7 @@
#include <QList>
#include <QPair>
#include <QFile>
#include <QFileInfo>
StaticFileServing::StaticFileServing (Hyperion *hyperion, QString baseUrl, quint16 port, QObject * parent)
: QObject (parent)
@ -75,12 +76,23 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl
return;
}
// get static files
if ( path == "/" || path.isEmpty() || ! QFile::exists(_baseUrl % "/" % path) )
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";
}
QFile file (_baseUrl % "/" % path);
if (file.exists ())
// get static files
QFile file(_baseUrl % "/" % path);
if (file.exists())
{
QMimeType mime = _mimeDb->mimeTypeForFile (file.fileName ());
if (file.open (QFile::ReadOnly)) {