QtWebApp
|
Stores HTTP sessions and deletes them when they have expired. More...
#include <httpsessionstore.h>
Signals | |
void | sessionDeleted (const QByteArray &sessionId) |
Emitted when the session is deleted. More... | |
Public Member Functions | |
HttpSessionStore (const QSettings *settings, QObject *parent=nullptr) | |
Constructor. More... | |
virtual | ~HttpSessionStore () |
Destructor. | |
QByteArray | getSessionId (HttpRequest &request, HttpResponse &response) |
Get the ID of the current HTTP session, if it is valid. More... | |
HttpSession | getSession (HttpRequest &request, HttpResponse &response, const bool allowCreate=true) |
Get the session of a HTTP request, eventually create a new one. More... | |
HttpSession | getSession (const QByteArray id) |
Get a HTTP session by it's ID number. More... | |
void | removeSession (const HttpSession session) |
Delete a session. | |
Protected Attributes | |
QMap< QByteArray, HttpSession > | sessions |
Storage for the sessions. | |
Stores HTTP sessions and deletes them when they have expired.
The following configuration settings are required in the config file:
expirationTime=3600000 cookieName=sessionid
The following additional configurations settings are optionally:
cookiePath=/ cookieComment=Session ID ;cookieDomain=stefanfrings.de
Definition at line 35 of file httpsessionstore.h.
HttpSessionStore::HttpSessionStore | ( | const QSettings * | settings, |
QObject * | parent = nullptr |
||
) |
Constructor.
settings | Configuration settings, usually stored in an INI file. Must not be 0. Settings are read from the current group, so the caller must have called settings->beginGroup(). Because the group must not change during runtime, it is recommended to provide a separate QSettings instance that is not used by other parts of the program. The HttpSessionStore does not take over ownership of the QSettings instance, so the caller should destroy it during shutdown. |
parent | Parent object |
Definition at line 12 of file httpsessionstore.cpp.
HttpSession HttpSessionStore::getSession | ( | const QByteArray | id | ) |
Get a HTTP session by it's ID number.
This method is thread safe.
id | ID number of the session |
Definition at line 93 of file httpsessionstore.cpp.
HttpSession HttpSessionStore::getSession | ( | HttpRequest & | request, |
HttpResponse & | response, | ||
const bool | allowCreate = true |
||
) |
Get the session of a HTTP request, eventually create a new one.
This method is thread safe. New sessions can only be created before the first byte has been written to the HTTP response.
request | Used to get the session cookie |
response | Used to get and set the new session cookie |
allowCreate | can be set to false, to disable the automatic creation of a new session. |
Definition at line 52 of file httpsessionstore.cpp.
QByteArray HttpSessionStore::getSessionId | ( | HttpRequest & | request, |
HttpResponse & | response | ||
) |
Get the ID of the current HTTP session, if it is valid.
This method is thread safe.
request | Used to get the session cookie |
response | Used to get and set the new session cookie |
Definition at line 28 of file httpsessionstore.cpp.
|
signal |
Emitted when the session is deleted.
sessionId | The ID number of the session. |