mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
implement 404 for webserver - this is a quick hack, should be refactored later (#378)
This commit is contained in:
parent
cde5a4dff1
commit
8a4d1c5088
@ -73,6 +73,13 @@ static inline void printErrorToReply (QtHttpReply * reply, QString errorMessage)
|
||||
reply->appendRawData (errorMessage.toLocal8Bit ());
|
||||
}
|
||||
|
||||
static inline void printError404ToReply (QtHttpReply * reply, QString errorMessage)
|
||||
{
|
||||
reply->setStatusCode(QtHttpReply::NotFound);
|
||||
reply->addHeader ("Content-Type", QByteArrayLiteral ("text/plain"));
|
||||
reply->appendRawData (errorMessage.toLocal8Bit ());
|
||||
}
|
||||
|
||||
void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpReply * reply)
|
||||
{
|
||||
QString command = request->getCommand ();
|
||||
@ -103,7 +110,7 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl
|
||||
Q_INIT_RESOURCE(WebConfig);
|
||||
|
||||
QFileInfo info(_baseUrl % "/" % path);
|
||||
if ( path == "/" || path.isEmpty() || ! info.exists() )
|
||||
if ( path == "/" || path.isEmpty() )
|
||||
{
|
||||
path = "index.html";
|
||||
}
|
||||
@ -134,7 +141,7 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl
|
||||
}
|
||||
else
|
||||
{
|
||||
printErrorToReply (reply, "Requested file " % path % " couldn't be found !");
|
||||
printError404ToReply (reply, "404 Not Found\n" % path % " couldn't be found !");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user