30 QString path = request->
path();
47 QString rootpath = QDir::fromNativeSeparators(
settings()->docroot());
51 response->
write(QString(
"500 server error: %1<br>\nRecursive loop detected in included files.").arg(path).toUtf8());
57 if (path.startsWith(
"/..") || path.startsWith(
"..")) {
59 response->
write(QString(
"403 Forbidden: %1<br>\nDo not use ../ in your file path").arg(path).toUtf8());
64 QString filename = rootpath +
"/" + path;
67 if (QFileInfo(filename).isDir()) {
69 response->
write(QString(
"500 Server error: %1<br>\nCannot include directory").arg(file.fileName()).toUtf8());
76 response->
write(QString(
"404 File not found: %1").arg(file.fileName()).toUtf8());
81 if (!file.open(QIODevice::ReadOnly)) {
83 response->
write(QString(
"403 Forbidden: %1").arg(file.fileName()).toUtf8());
88 while (!file.atEnd()) {
89 QString line = QString::fromUtf8(file.readLine());
90 if (line.contains(QRegExp(
"^\\s*<!--\\s*#include\\s+\".+\"\\s*-->\\s*$"))) {
91 QStringList lineparts = line.split(
'"');
92 if (lineparts.size() != 3) {
98 data += line.toUtf8();
void service(HttpRequest *request, HttpResponse *response)
Processes one request.
HttpResponse * response()
Returns new instance of HttpResponse class.
QString path() const
Returns path of the request (/files/index.html)
void flush()
Writes last part of the response and closes the socket when possible.
Response to HTTP request - headers, cookies and body.
void write(const QByteArray &data)
Writes data to response body.
Processes incoming requests.
const HttpSettings * settings() const
Returns pointer to HttpSettings used in the HttpServer.
QByteArray readFile(const QString &path, HttpResponse *response, int depth)
Reads and processes one file, other files can be included recursivelly.
Processes HTTP request, parses headers, body and files sent by HTTP protocol.
void setStatus(int code, const QString &description=QString())
Set the status code and the description of the response.
void setHeader(const QString &name, const QString &value)
Sets or rewrite one header.
ShtmlController(HttpConnection *parent)
Construct sets the default parameter from configuration (encoding and root)
Namespace of HTTP server.
One single connection to http server.