forked from dedis/Dissent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGetDirectoryService.cpp
48 lines (40 loc) · 1.01 KB
/
GetDirectoryService.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <QtCore>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QUrlQuery>
#endif
#include "GetDirectoryService.hpp"
namespace Dissent {
namespace Web {
GetDirectoryService::GetDirectoryService(const QString &path) :
_webpath(path)
{
}
GetDirectoryService::~GetDirectoryService()
{
}
const QString GetDirectoryService::_file_name = "file";
void GetDirectoryService::HandleRequest(QHttpRequest *request,
QHttpResponse *response)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QString filename = request->url().queryItemValue(_file_name);
#else
QString filename = QUrlQuery(request->url()).queryItemValue(_file_name);
#endif
if(filename.isEmpty()) {
filename = "index.html";
}
QFile file(_webpath + "/" + filename);
if(!file.exists()) {
SendNotFound(response);
return;
}
QByteArray outputData;
if(file.open(QIODevice::ReadOnly)){
outputData = file.readAll();
}
file.close();
SendResponse(response, outputData);
}
}
}