kopia lustrzana https://github.com/f4exb/sdrangel
HttpServer: use settings structures in place of QSettings
rodzic
bc793b4095
commit
9a77311b2a
|
@ -26,6 +26,9 @@ set(httpserver_HEADERS
|
||||||
httpsession.h
|
httpsession.h
|
||||||
httpsessionstore.h
|
httpsessionstore.h
|
||||||
staticfilecontroller.h
|
staticfilecontroller.h
|
||||||
|
httplistenersettings.h
|
||||||
|
httpdocrootsettings.h
|
||||||
|
httpsessionssettings.h
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* httpdocrootsettings.h
|
||||||
|
*
|
||||||
|
* Created on: Nov 13, 2017
|
||||||
|
* Author: f4exb
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HTTPSERVER_HTTPDOCROOTSETTINGS_H_
|
||||||
|
#define HTTPSERVER_HTTPDOCROOTSETTINGS_H_
|
||||||
|
|
||||||
|
namespace qtwebapp {
|
||||||
|
|
||||||
|
struct HttpDocrootSettings
|
||||||
|
{
|
||||||
|
QString path;
|
||||||
|
QString encoding;
|
||||||
|
int maxAge;
|
||||||
|
int cacheTime;
|
||||||
|
int cacheSize;
|
||||||
|
int maxCachedFileSize;
|
||||||
|
|
||||||
|
HttpDocrootSettings() {
|
||||||
|
resetToDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetToDefaults()
|
||||||
|
{
|
||||||
|
path = ".";
|
||||||
|
encoding = "UTF-8";
|
||||||
|
maxAge = 60000;
|
||||||
|
cacheTime = 60000;
|
||||||
|
cacheSize = 1000000;
|
||||||
|
maxCachedFileSize = 65536;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end of namespace
|
||||||
|
|
||||||
|
#endif /* HTTPSERVER_HTTPDOCROOTSETTINGS_H_ */
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* httplistenersettings.h
|
||||||
|
*
|
||||||
|
* Created on: Nov 13, 2017
|
||||||
|
* Author: f4exb
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HTTPSERVER_HTTPLISTENERSETTINGS_H_
|
||||||
|
#define HTTPSERVER_HTTPLISTENERSETTINGS_H_
|
||||||
|
|
||||||
|
namespace qtwebapp {
|
||||||
|
|
||||||
|
struct HttpListenerSettings
|
||||||
|
{
|
||||||
|
QString host;
|
||||||
|
int port;
|
||||||
|
int minThreads;
|
||||||
|
int maxThreads;
|
||||||
|
int cleanupInterval;
|
||||||
|
int readTimeout;
|
||||||
|
QString sslKeyFile;
|
||||||
|
QString sslCertFile;
|
||||||
|
int maxRequestSize;
|
||||||
|
int maxMultiPartSize;
|
||||||
|
|
||||||
|
HttpListenerSettings() {
|
||||||
|
resetToDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetToDefaults()
|
||||||
|
{
|
||||||
|
host = "192.168.0.100";
|
||||||
|
port = 8080;
|
||||||
|
minThreads = 1;
|
||||||
|
maxThreads = 100;
|
||||||
|
cleanupInterval = 1000;
|
||||||
|
readTimeout = 10000;
|
||||||
|
sslKeyFile = "";
|
||||||
|
sslCertFile = "";
|
||||||
|
maxRequestSize = 16000;
|
||||||
|
maxMultiPartSize = 1000000;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end of namespace
|
||||||
|
|
||||||
|
#endif /* HTTPSERVER_HTTPLISTENERSETTINGS_H_ */
|
|
@ -30,7 +30,11 @@ HEADERS += $$PWD/httpglobal.h \
|
||||||
$$PWD/httprequesthandler.h \
|
$$PWD/httprequesthandler.h \
|
||||||
$$PWD/httpsession.h \
|
$$PWD/httpsession.h \
|
||||||
$$PWD/httpsessionstore.h \
|
$$PWD/httpsessionstore.h \
|
||||||
$$PWD/staticfilecontroller.h
|
$$PWD/staticfilecontroller.h \
|
||||||
|
$$PWD/httplistenersettings.h \
|
||||||
|
$$PWD/httpdocrootsettings.h \
|
||||||
|
$$PWD/httpsessionssettings.h
|
||||||
|
|
||||||
|
|
||||||
SOURCES += $$PWD/httpglobal.cpp \
|
SOURCES += $$PWD/httpglobal.cpp \
|
||||||
$$PWD/httplistener.cpp \
|
$$PWD/httplistener.cpp \
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* httpsessionssettings.h
|
||||||
|
*
|
||||||
|
* Created on: Nov 13, 2017
|
||||||
|
* Author: f4exb
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HTTPSERVER_HTTPSESSIONSSETTINGS_H_
|
||||||
|
#define HTTPSERVER_HTTPSESSIONSSETTINGS_H_
|
||||||
|
|
||||||
|
namespace qtwebapp {
|
||||||
|
|
||||||
|
struct HttpSessionsSettings
|
||||||
|
{
|
||||||
|
int expirationTime;
|
||||||
|
QString cookieName;
|
||||||
|
QString cookiePath;
|
||||||
|
QString cookieComment;
|
||||||
|
QString cookieDomain;
|
||||||
|
|
||||||
|
HttpSessionsSettings() {
|
||||||
|
resetToDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetToDefaults()
|
||||||
|
{
|
||||||
|
expirationTime = 3600000;
|
||||||
|
cookieName = "sessionid";
|
||||||
|
cookiePath = "";
|
||||||
|
cookieComment = "";
|
||||||
|
cookieDomain = "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end of namespace
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* HTTPSERVER_HTTPSESSIONSSETTINGS_H_ */
|
|
@ -4,6 +4,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "staticfilecontroller.h"
|
#include "staticfilecontroller.h"
|
||||||
|
#include "httpdocrootsettings.h"
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
@ -11,7 +13,7 @@
|
||||||
using namespace qtwebapp;
|
using namespace qtwebapp;
|
||||||
|
|
||||||
StaticFileController::StaticFileController(QSettings* settings, QObject* parent)
|
StaticFileController::StaticFileController(QSettings* settings, QObject* parent)
|
||||||
:HttpRequestHandler(parent)
|
:HttpRequestHandler(parent), useQtSettings(true)
|
||||||
{
|
{
|
||||||
maxAge=settings->value("maxAge","60000").toInt();
|
maxAge=settings->value("maxAge","60000").toInt();
|
||||||
encoding=settings->value("encoding","UTF-8").toString();
|
encoding=settings->value("encoding","UTF-8").toString();
|
||||||
|
@ -36,6 +38,26 @@ StaticFileController::StaticFileController(QSettings* settings, QObject* parent)
|
||||||
qDebug("StaticFileController: cache timeout=%i, size=%i",cacheTimeout,cache.maxCost());
|
qDebug("StaticFileController: cache timeout=%i, size=%i",cacheTimeout,cache.maxCost());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StaticFileController::StaticFileController(HttpDocrootSettings* settings, QObject* parent)
|
||||||
|
:HttpRequestHandler(parent), useQtSettings(false)
|
||||||
|
{
|
||||||
|
maxAge=settings->maxAge;
|
||||||
|
encoding=settings->encoding;
|
||||||
|
docroot=settings->path;
|
||||||
|
if(!(docroot.startsWith(":/") || docroot.startsWith("qrc://")))
|
||||||
|
{
|
||||||
|
// Convert relative path to absolute, based on the directory of the config file.
|
||||||
|
if (QDir::isRelativePath(docroot))
|
||||||
|
{
|
||||||
|
docroot = QFileInfo(QDir::currentPath(), docroot).absoluteFilePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug("StaticFileController: docroot=%s, encoding=%s, maxAge=%i",qPrintable(docroot),qPrintable(encoding),maxAge);
|
||||||
|
maxCachedFileSize=settings->maxCachedFileSize;
|
||||||
|
cache.setMaxCost(settings->cacheSize);
|
||||||
|
cacheTimeout=settings->cacheTime;
|
||||||
|
qDebug("StaticFileController: cache timeout=%i, size=%i",cacheTimeout,cache.maxCost());
|
||||||
|
}
|
||||||
|
|
||||||
void StaticFileController::service(HttpRequest& request, HttpResponse& response)
|
void StaticFileController::service(HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,6 +42,8 @@ namespace qtwebapp {
|
||||||
received a related HTTP request.
|
received a related HTTP request.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class HttpDocrootSettings;
|
||||||
|
|
||||||
class DECLSPEC StaticFileController : public HttpRequestHandler {
|
class DECLSPEC StaticFileController : public HttpRequestHandler {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DISABLE_COPY(StaticFileController)
|
Q_DISABLE_COPY(StaticFileController)
|
||||||
|
@ -50,6 +52,9 @@ public:
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
StaticFileController(QSettings* settings, QObject* parent = NULL);
|
StaticFileController(QSettings* settings, QObject* parent = NULL);
|
||||||
|
|
||||||
|
/** Constructor */
|
||||||
|
StaticFileController(HttpDocrootSettings* settings, QObject* parent = NULL);
|
||||||
|
|
||||||
/** Generates the response */
|
/** Generates the response */
|
||||||
void service(HttpRequest& request, HttpResponse& response);
|
void service(HttpRequest& request, HttpResponse& response);
|
||||||
|
|
||||||
|
@ -82,6 +87,9 @@ private:
|
||||||
/** Used to synchronize cache access for threads */
|
/** Used to synchronize cache access for threads */
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
|
|
||||||
|
/** Settings flag */
|
||||||
|
bool useQtSettings;
|
||||||
|
|
||||||
/** Set a content-type header in the response depending on the ending of the filename */
|
/** Set a content-type header in the response depending on the ending of the filename */
|
||||||
void setContentType(QString file, HttpResponse& response) const;
|
void setContentType(QString file, HttpResponse& response) const;
|
||||||
};
|
};
|
||||||
|
|
Ładowanie…
Reference in New Issue