24 QHash<QString, QString> StaticFileController::m_mimetypes;
28 if (m_mimetypes.isEmpty()) {
48 return m_parent->settings();
53 m_mimetypes[fileSuffix] = mimetype;
58 QString path = request->
path();
59 QString rootpath = QDir::fromNativeSeparators(
settings()->docroot());
61 if (path.startsWith(
"/..")) {
68 QString filename = QDir::fromNativeSeparators(rootpath + path);
69 QFileInfo fileinfo(filename);
70 if (fileinfo.isDir()) {
71 filename +=
"/" + QDir::fromNativeSeparators(
settings()->indexFile());
72 fileinfo.setFile(filename);
75 QFile file(fileinfo.canonicalFilePath());
83 if (!file.open(QIODevice::ReadOnly)) {
90 QString suffix = fileinfo.suffix();
91 if (!suffix.isEmpty() && m_mimetypes.contains(suffix)) {
102 QString StaticFileController::toGMTString(
const QDateTime& x) {
104 switch (x.date().dayOfWeek()) {
105 case 1: dayname =
"Mon";
break;
106 case 2: dayname =
"Tue";
break;
107 case 3: dayname =
"Wed";
break;
108 case 4: dayname =
"Thu";
break;
109 case 5: dayname =
"Fri";
break;
110 case 6: dayname =
"Sat";
break;
111 case 7: dayname =
"Sun";
break;
115 switch (x.date().month()) {
116 case 1: monthname =
"Jan";
break;
117 case 2: monthname =
"Feb";
break;
118 case 3: monthname =
"Mar";
break;
119 case 4: monthname =
"Apr";
break;
120 case 5: monthname =
"May";
break;
121 case 6: monthname =
"Jun";
break;
122 case 7: monthname =
"Jul";
break;
123 case 8: monthname =
"Aug";
break;
124 case 9: monthname =
"Sep";
break;
125 case 10: monthname =
"Oct";
break;
126 case 11: monthname =
"Nov";
break;
127 case 12: monthname =
"Dec";
break;
130 QString
string = QString(
"%1, %2 %3 %4 %5:%6:%7 GMT")
134 .arg(x.date().year())
135 .arg(x.time().hour())
136 .arg(x.time().minute())
137 .arg(x.time().second())
HttpResponse * response()
Returns new instance of HttpResponse class.
QString path() const
Returns path of the request (/files/index.html)
StaticFileController(HttpConnection *parent)
Constructor set default parameters from configuration.
void addMimeType(const QString &fileSuffix, const QString &mimetype)
Adds mime type to static table of mime types (common for all class instances)
void flush()
Writes last part of the response and closes the socket when possible.
const HttpSettings * settings() const
Returs pointer to HttpSettings used in the HttpServer.
Response to HTTP request - headers, cookies and body.
void write(const QByteArray &data)
Writes data to response body.
void service(HttpRequest *request, HttpResponse *response)
Processes the request.
Configuration of the http server instance.
Processes incoming requests.
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.
Namespace of HTTP server.
One single connection to http server.