10 using namespace stefanfrings;
15 this->settings=settings;
16 connect(&cleanupTimer,SIGNAL(timeout()),
this,SLOT(sessionTimerEvent()));
17 cleanupTimer.start(60000);
18 cookieName=settings->value(
"cookieName",
"sessionid").toByteArray();
19 expirationTime=settings->value(
"expirationTime",3600000).toInt();
20 qDebug(
"HttpSessionStore: Sessions expire after %i milliseconds",expirationTime);
33 QByteArray sessionId=response.
getCookies().value(cookieName).getValue();
34 if (sessionId.isEmpty())
40 if (!sessionId.isEmpty())
44 qDebug(
"HttpSessionStore: received invalid session cookie with ID %s",sessionId.data());
56 if (!sessionId.isEmpty())
63 QByteArray cookieName=settings->value(
"cookieName",
"sessionid").toByteArray();
64 QByteArray cookiePath=settings->value(
"cookiePath").toByteArray();
65 QByteArray cookieComment=settings->value(
"cookieComment").toByteArray();
66 QByteArray cookieDomain=settings->value(
"cookieDomain").toByteArray();
68 cookiePath,cookieComment,cookieDomain,
false,
false,
"Lax"));
76 QByteArray cookieName=settings->value(
"cookieName",
"sessionid").toByteArray();
77 QByteArray cookiePath=settings->value(
"cookiePath").toByteArray();
78 QByteArray cookieComment=settings->value(
"cookieComment").toByteArray();
79 QByteArray cookieDomain=settings->value(
"cookieDomain").toByteArray();
81 qDebug(
"HttpSessionStore: create new session with ID %s",session.
getId().data());
84 cookiePath,cookieComment,cookieDomain,
false,
false,
"Lax"));
102 void HttpSessionStore::sessionTimerEvent()
105 qint64 now=QDateTime::currentMSecsSinceEpoch();
106 QMap<QByteArray,HttpSession>::iterator i =
sessions.begin();
109 QMap<QByteArray,HttpSession>::iterator prev = i;
113 if (now-lastAccess>expirationTime)
115 qDebug(
"HttpSessionStore: session %s expired",session.
getId().data());
HTTP cookie as defined in RFC 2109.
This object represents a single HTTP request.
QByteArray getCookie(const QByteArray &name) const
Get the value of a cookie.
This object represents a HTTP response, used to return something to the web client.
QMap< QByteArray, HttpCookie > & getCookies()
Get the map of cookies.
void setCookie(const HttpCookie &cookie)
Set a cookie.
virtual ~HttpSessionStore()
Destructor.
QMap< QByteArray, HttpSession > sessions
Storage for the sessions.
void removeSession(const HttpSession session)
Delete a session.
HttpSessionStore(const QSettings *settings, QObject *parent=nullptr)
Constructor.
QByteArray getSessionId(HttpRequest &request, HttpResponse &response)
Get the ID of the current HTTP session, if it is valid.
void sessionDeleted(const QByteArray &sessionId)
Emitted when the session is deleted.
HttpSession getSession(HttpRequest &request, HttpResponse &response, const bool allowCreate=true)
Get the session of a HTTP request, eventually create a new one.
This class stores data for a single HTTP session.
bool isNull() const
Null sessions cannot store data.
void setLastAccess()
Set the timestamp of last access, to renew the timeout period.
QByteArray getId() const
Get the unique ID of this session.
qint64 getLastAccess() const
Get the timestamp of last access.