Stellarium 0.15.2
staticfilecontroller.h
Go to the documentation of this file.
1 
6 #ifndef STATICFILECONTROLLER_H
7 #define STATICFILECONTROLLER_H
8 
9 #include <QCache>
10 #include <QMutex>
11 #include "httpglobal.h"
12 #include "httprequest.h"
13 #include "httpresponse.h"
14 #include "httprequesthandler.h"
15 
21 {
23  : encoding("UTF-8"),maxAge(60),cacheTime(60000),cacheSize(1048576),maxCachedFileSize(65536)
24  {}
25 
27  QString path;
29  QString encoding;
31  int maxAge;
33  int cacheTime;
35  int cacheSize;
38 };
39 
40 
69 class DECLSPEC StaticFileController : public HttpRequestHandler {
70  Q_OBJECT
71  Q_DISABLE_COPY(StaticFileController)
72 public:
73 
75  StaticFileController(const StaticFileControllerSettings& settings, QObject* parent = NULL);
76 
78  void service(HttpRequest& request, HttpResponse& response);
79 
80  QString getDocRoot() const { return docroot; }
81 
83  static QByteArray getContentType(QString fileName, QString encoding);
84 private:
85 
87  QString encoding;
88 
90  QString docroot;
91 
93  int maxAge;
94 
95  struct CacheEntry {
96  QByteArray document;
97  qint64 created;
98  QByteArray filename;
99  };
100 
102  int cacheTimeout;
103 
105  int maxCachedFileSize;
106 
108  QCache<QString,CacheEntry> cache;
109 
111  QMutex mutex;
112 
114  void setContentType(QString file, HttpResponse& response) const;
115 };
116 
117 #endif // STATICFILECONTROLLER_H
int maxCachedFileSize
Maximum size of a single file in the serverside cache.
The request handler generates a response for each HTTP request.
QString path
The path to the document root.
Contains all the settings for the StaticFileController.
int cacheSize
Total serverside cache size in bytes.
int maxAge
Maximum age of files in the browser cache (HTTP Cache-Control: max-age), in seconds.
QString encoding
The assumed encoding of textual files (txt, html).
This object represents a single HTTP request.
Definition: httprequest.h:36
int cacheTime
Maximum age of files in the serverside cache (in msec).
Delivers static files.
This object represents a HTTP response, used to return something to the web client.
Definition: httpresponse.h:35