QtWebApp
stefanfrings::HttpSessionStore Class Reference

Stores HTTP sessions and deletes them when they have expired. More...

#include <httpsessionstore.h>

Inheritance diagram for stefanfrings::HttpSessionStore:
Collaboration diagram for stefanfrings::HttpSessionStore:

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, HttpSessionsessions
 Storage for the sessions.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ HttpSessionStore()

HttpSessionStore::HttpSessionStore ( const QSettings *  settings,
QObject *  parent = nullptr 
)

Constructor.

Parameters
settingsConfiguration 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.
parentParent object

Definition at line 12 of file httpsessionstore.cpp.

Member Function Documentation

◆ getSession() [1/2]

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.

Parameters
requestUsed to get the session cookie
responseUsed to get and set the new session cookie
allowCreatecan be set to false, to disable the automatic creation of a new session.
Returns
If autoCreate is disabled, the function returns a null session if there is no session.
See also
HttpSession::isNull()

Definition at line 52 of file httpsessionstore.cpp.

◆ getSession() [2/2]

HttpSession HttpSessionStore::getSession ( const QByteArray  id)

Get a HTTP session by it's ID number.

This method is thread safe.

Returns
If there is no such session, the function returns a null session.
Parameters
idID number of the session
See also
HttpSession::isNull()

Definition at line 91 of file httpsessionstore.cpp.

◆ getSessionId()

QByteArray HttpSessionStore::getSessionId ( HttpRequest request,
HttpResponse response 
)

Get the ID of the current HTTP session, if it is valid.

This method is thread safe.

Warning
Sessions may expire at any time, so subsequent calls of getSession() might return a new session with a different ID.
Parameters
requestUsed to get the session cookie
responseUsed to get and set the new session cookie
Returns
Empty string, if there is no valid session.

Definition at line 28 of file httpsessionstore.cpp.


The documentation for this class was generated from the following files: