Malloy
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | List of all members
malloy::http::sessions::session Struct Referenceabstract

#include <session.hpp>

Inheritance diagram for malloy::http::sessions::session:
Inheritance graph
[legend]

Public Types

using key_type = std::string
 
using value_type = std::string
 
using id_type = std::string
 

Public Member Functions

 session (id_type &&id)
 
virtual ~session ()=default
 
 session (const session &other)=delete
 
 session (session &&other) noexcept=delete
 
sessionoperator= (const session &other)=delete
 
sessionoperator= (session &&other) noexcept=delete
 
bool set (const key_type &key, value_type value)
 
std::optional< key_type > get (const key_type &key)
 
virtual bool remove (const key_type &key)
 
id_type id () const noexcept
 
cookie generate_cookie (std::string cookie_name) const
 

Protected Member Functions

virtual bool storage_set (const key_type &key, value_type value)=0
 
virtual std::optional< value_type > storage_get (const key_type &key) const =0
 
virtual bool storage_remove (const key_type &key)=0
 
virtual void update_access_time ()=0
 

Detailed Description

This class represents a session.

This is a classic implementation for achieving a stateful session over stateless HTTP. It works by generating a server-side session using an object of this class and sending the session ID to the client as a cookie. The client will send back this cookie on sub-sequent requests through which the server can retrieve the corresponding session ID.

Constructor & Destructor Documentation

◆ session() [1/3]

malloy::http::sessions::session::session ( id_type &&  id)
inlineexplicit

Constructor.

Note
Sub-classes must call update_access_time() in their constructor.
Parameters
idThe session ID.

◆ ~session()

virtual malloy::http::sessions::session::~session ( )
virtualdefault

Destructor.

◆ session() [2/3]

malloy::http::sessions::session::session ( const session other)
delete

Copy constructor.

Parameters
other

◆ session() [3/3]

malloy::http::sessions::session::session ( session &&  other)
deletenoexcept

Move constructor

Parameters
other

Member Function Documentation

◆ generate_cookie()

cookie malloy::http::sessions::session::generate_cookie ( std::string  cookie_name) const
inline

Generates a session cookie for this session.

Parameters
cookie_nameThe cookie name.
Returns
The session cookie.

◆ get()

std::optional< key_type > malloy::http::sessions::session::get ( const key_type &  key)
inline

Get the value of a particular key.

Parameters
keyThe key.
Returns
The value corresponding to the specified key (if any).
Here is the call graph for this function:

◆ id()

id_type malloy::http::sessions::session::id ( ) const
inlinenoexcept

Get the session ID.

Returns
The session ID.

◆ operator=() [1/2]

session & malloy::http::sessions::session::operator= ( const session other)
delete

Copy assignment operator.

Parameters
other
Returns

◆ operator=() [2/2]

session & malloy::http::sessions::session::operator= ( session &&  other)
deletenoexcept

Move assignment operator.

Parameters
other
Returns

◆ remove()

virtual bool malloy::http::sessions::session::remove ( const key_type &  key)
inlinevirtual

Remove a key-value pair.

Parameters
keyThe key.
Returns
Whether a key-value pair was removed.
Here is the call graph for this function:

◆ set()

bool malloy::http::sessions::session::set ( const key_type &  key,
value_type  value 
)
inline

Add or update a key-value pair.

If the specified key does not exist yet, a new key-value pair will be created. If the key exists, the current value will be updated.

Parameters
keyThe key.
valueThe value.
Returns
Whether setting the value was successful.
Here is the call graph for this function:

◆ storage_get()

virtual std::optional< value_type > malloy::http::sessions::session::storage_get ( const key_type &  key) const
protectedpure virtual

Get the value of a particular key.

Parameters
keyThe key.
Returns
The value corresponding to the specified key (if any).

◆ storage_remove()

virtual bool malloy::http::sessions::session::storage_remove ( const key_type &  key)
protectedpure virtual

Remove a key-value pair.

Parameters
keyThe key.
Returns
Whether a key-value pair was removed.

◆ storage_set()

virtual bool malloy::http::sessions::session::storage_set ( const key_type &  key,
value_type  value 
)
protectedpure virtual

Add or update a key-value pair.

If the specified key does not exist yet, a new key-value pair will be created. If the key exists, the current value will be updated.

Parameters
keyThe key.
valueThe value.
Returns
Whether setting the value was successful.

◆ update_access_time()

virtual void malloy::http::sessions::session::update_access_time ( )
protectedpure virtual

Update the access time.

This should usually update the access time to the current time.

Implemented in malloy::http::sessions::session_chrono< Clock >, and malloy::http::sessions::session_chrono< std::chrono::steady_clock >.


The documentation for this struct was generated from the following file: