1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-23 21:14:33 +00:00

Merge pull request #6548 from Chocobo1/cookie

Fixes for AbstractWebApplication
This commit is contained in:
sledgehammer999 2017-04-05 18:37:51 +03:00 committed by GitHub
commit 1111ca9d90
2 changed files with 17 additions and 23 deletions

View File

@ -87,8 +87,8 @@ AbstractWebApplication::AbstractWebApplication(QObject *parent)
, session_(0) , session_(0)
{ {
QTimer *timer = new QTimer(this); QTimer *timer = new QTimer(this);
timer->setInterval(60000); // 1 min.
connect(timer, SIGNAL(timeout()), SLOT(removeInactiveSessions())); connect(timer, SIGNAL(timeout()), SLOT(removeInactiveSessions()));
timer->start(60 * 1000); // 1 min.
} }
AbstractWebApplication::~AbstractWebApplication() AbstractWebApplication::~AbstractWebApplication()
@ -354,6 +354,7 @@ bool AbstractWebApplication::sessionStart()
sessions_[session_->id] = session_; sessions_[session_->id] = session_;
QNetworkCookie cookie(C_SID, session_->id.toUtf8()); QNetworkCookie cookie(C_SID, session_->id.toUtf8());
cookie.setHttpOnly(true);
cookie.setPath(QLatin1String("/")); cookie.setPath(QLatin1String("/"));
header(Http::HEADER_SET_COOKIE, cookie.toRawForm()); header(Http::HEADER_SET_COOKIE, cookie.toRawForm());
@ -366,9 +367,9 @@ bool AbstractWebApplication::sessionStart()
bool AbstractWebApplication::sessionEnd() bool AbstractWebApplication::sessionEnd()
{ {
if ((session_ != 0) && (sessions_.contains(session_->id))) { if ((session_ != 0) && (sessions_.contains(session_->id))) {
QNetworkCookie cookie(C_SID, session_->id.toUtf8()); QNetworkCookie cookie(C_SID);
cookie.setPath(QLatin1String("/")); cookie.setPath(QLatin1String("/"));
cookie.setExpirationDate(QDateTime::currentDateTime()); cookie.setExpirationDate(QDateTime::currentDateTime().addDays(-1));
sessions_.remove(session_->id); sessions_.remove(session_->id);
delete session_; delete session_;
@ -395,18 +396,11 @@ QString AbstractWebApplication::saveTmpFile(const QByteArray &data)
return QString(); return QString();
} }
QStringMap AbstractWebApplication::initializeContentTypeByExtMap() const QStringMap AbstractWebApplication::CONTENT_TYPE_BY_EXT = {
{ { "htm", Http::CONTENT_TYPE_HTML },
QStringMap map; { "html", Http::CONTENT_TYPE_HTML },
{ "css", Http::CONTENT_TYPE_CSS },
map["htm"] = Http::CONTENT_TYPE_HTML; { "gif", Http::CONTENT_TYPE_GIF },
map["html"] = Http::CONTENT_TYPE_HTML; { "png", Http::CONTENT_TYPE_PNG },
map["css"] = Http::CONTENT_TYPE_CSS; { "js", Http::CONTENT_TYPE_JS }
map["gif"] = Http::CONTENT_TYPE_GIF; };
map["png"] = Http::CONTENT_TYPE_PNG;
map["js"] = Http::CONTENT_TYPE_JS;
return map;
}
const QStringMap AbstractWebApplication::CONTENT_TYPE_BY_EXT = AbstractWebApplication::initializeContentTypeByExtMap();

View File

@ -29,12 +29,13 @@
#ifndef ABSTRACTWEBAPPLICATION_H #ifndef ABSTRACTWEBAPPLICATION_H
#define ABSTRACTWEBAPPLICATION_H #define ABSTRACTWEBAPPLICATION_H
#include <QObject>
#include <QMap>
#include <QHash> #include <QHash>
#include "base/http/types.h" #include <QMap>
#include "base/http/responsebuilder.h" #include <QObject>
#include "base/http/irequesthandler.h" #include "base/http/irequesthandler.h"
#include "base/http/responsebuilder.h"
#include "base/http/types.h"
struct WebSession; struct WebSession;
struct WebSessionData; struct WebSessionData;
@ -102,7 +103,6 @@ private:
static void translateDocument(QString &data); static void translateDocument(QString &data);
static const QStringMap CONTENT_TYPE_BY_EXT; static const QStringMap CONTENT_TYPE_BY_EXT;
static QStringMap initializeContentTypeByExtMap();
}; };
#endif // ABSTRACTWEBAPPLICATION_H #endif // ABSTRACTWEBAPPLICATION_H