summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorten Sorvig <msorvig@trolltech.com>2009-09-07 06:25:35 +0200
committerMorten Sorvig <msorvig@trolltech.com>2009-09-07 06:25:35 +0200
commit5e650ba413d2fc730ae923802bf4ebd2e694f0e3 (patch)
tree4a68513515398882b2f866974524178a46f5614b
parent6f44e6e7759a4bf57b9662754d8ea984d9a02eff (diff)
Pre-load the static files at server startup
-rw-r--r--src/webclientserver.cpp39
-rw-r--r--src/webclientserver.h2
2 files changed, 19 insertions, 22 deletions
diff --git a/src/webclientserver.cpp b/src/webclientserver.cpp
index 0e32717..bb80223 100644
--- a/src/webclientserver.cpp
+++ b/src/webclientserver.cpp
@@ -418,6 +418,21 @@ FileServer::FileServer()
<< ":qwebclient.css" << ":dojo.js"
<< ":json2.js" << ":draghandler.js"
<< ":sessionhandler.js" << ":eventhandler.js";
+
+ foreach (const QString &fileName, allowedFileNames) {
+ QFile file(fileName);
+ if (file.exists() == false) {
+// DEBUG << "no file" << filePath;
+ continue;
+ }
+
+ file.open(QIODevice::ReadOnly);
+ QByteArray fileContents = file.readAll();
+ //fileContents.replace("INSERT_HOSTNAME", request->hostName());
+ fileData[fileName] = fileContents;
+ fileDataDeflated[fileName] = qCompress(fileContents);
+ eTags[fileName] = QByteArray::number(qHash(fileContents));
+ }
}
void FileServer::handleRequest(HttpRequest *request, HttpResponse *response)
@@ -436,11 +451,6 @@ void FileServer::handleRequest(HttpRequest *request, HttpResponse *response)
if (allowedFileNames.contains(filePath) == false)
return; // ### drop connection?
- QFile file(filePath);
- if (file.exists() == false) {
-// DEBUG << "no file" << filePath;
- return;
- }
// Check if the client sends an If-None-Match, return
// 304 Not Modified if it matches the server's eTag
@@ -453,21 +463,6 @@ void FileServer::handleRequest(HttpRequest *request, HttpResponse *response)
}
}
- file.open(QIODevice::ReadOnly);
- QByteArray fileContents = file.readAll();
- fileContents.replace("INSERT_HOSTNAME", request->hostName());
- static int pageId = 0;
-
-/*
- if (fileContents.contains("INSERT_PAGE_ID"))
- fileContents.replace("INSERT_PAGE_ID", QByteArray::number(++pageId));
-*/
- QByteArray eTag = eTags[filePath];
- if (eTag.isEmpty()) {
- eTag = QByteArray::number(qHash(fileContents));
- eTags[filePath] = eTag;
- }
-
- response->seteTag(eTag);
- response->setBody(fileContents);
+ response->seteTag(eTags[filePath]);
+ response->setBody(fileData[filePath]);
}
diff --git a/src/webclientserver.h b/src/webclientserver.h
index fa4818b..032b101 100644
--- a/src/webclientserver.h
+++ b/src/webclientserver.h
@@ -86,6 +86,8 @@ public slots:
virtual void handleRequest(HttpRequest *request, HttpResponse *response);
private:
QSet<QString> allowedFileNames;
+ QHash<QString, QByteArray> fileData;
+ QHash<QString, QByteArray> fileDataDeflated;
QHash<QString, QByteArray> eTags;
};