mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-21 15:51:47 -05:00
HttpServer: use settings structures in place of QSettings
This commit is contained in:
parent
bc793b4095
commit
9a77311b2a
@ -26,6 +26,9 @@ set(httpserver_HEADERS
|
||||
httpsession.h
|
||||
httpsessionstore.h
|
||||
staticfilecontroller.h
|
||||
httplistenersettings.h
|
||||
httpdocrootsettings.h
|
||||
httpsessionssettings.h
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
39
httpserver/httpdocrootsettings.h
Normal file
39
httpserver/httpdocrootsettings.h
Normal file
@ -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_ */
|
47
httpserver/httplistenersettings.h
Normal file
47
httpserver/httplistenersettings.h
Normal file
@ -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/httpsession.h \
|
||||
$$PWD/httpsessionstore.h \
|
||||
$$PWD/staticfilecontroller.h
|
||||
$$PWD/staticfilecontroller.h \
|
||||
$$PWD/httplistenersettings.h \
|
||||
$$PWD/httpdocrootsettings.h \
|
||||
$$PWD/httpsessionssettings.h
|
||||
|
||||
|
||||
SOURCES += $$PWD/httpglobal.cpp \
|
||||
$$PWD/httplistener.cpp \
|
||||
|
40
httpserver/httpsessionssettings.h
Normal file
40
httpserver/httpsessionssettings.h
Normal file
@ -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 "httpdocrootsettings.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QDateTime>
|
||||
@ -11,7 +13,7 @@
|
||||
using namespace qtwebapp;
|
||||
|
||||
StaticFileController::StaticFileController(QSettings* settings, QObject* parent)
|
||||
:HttpRequestHandler(parent)
|
||||
:HttpRequestHandler(parent), useQtSettings(true)
|
||||
{
|
||||
maxAge=settings->value("maxAge","60000").toInt();
|
||||
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());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -42,6 +42,8 @@ namespace qtwebapp {
|
||||
received a related HTTP request.
|
||||
*/
|
||||
|
||||
class HttpDocrootSettings;
|
||||
|
||||
class DECLSPEC StaticFileController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(StaticFileController)
|
||||
@ -50,6 +52,9 @@ public:
|
||||
/** Constructor */
|
||||
StaticFileController(QSettings* settings, QObject* parent = NULL);
|
||||
|
||||
/** Constructor */
|
||||
StaticFileController(HttpDocrootSettings* settings, QObject* parent = NULL);
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
@ -82,6 +87,9 @@ private:
|
||||
/** Used to synchronize cache access for threads */
|
||||
QMutex mutex;
|
||||
|
||||
/** Settings flag */
|
||||
bool useQtSettings;
|
||||
|
||||
/** Set a content-type header in the response depending on the ending of the filename */
|
||||
void setContentType(QString file, HttpResponse& response) const;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user