cutelyst 3.9.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Cutelyst::Cookie Class Reference

The Cutelyst Cookie. More...

#include <Cutelyst/Cookie>

Inheritance diagram for Cutelyst::Cookie:

Public Types

enum class  SameSite { Default , None , Lax , Strict }
Public Types inherited from QNetworkCookie
enum  RawForm

Public Member Functions

 Cookie (const Cookie &other)
 Creates a new Cookie object by copying the contents of other.
 Cookie (const QByteArray &name=QByteArray(), const QByteArray &value=QByteArray())
 Create a new Cookie object, initializing the cookie name to name and its value to value.
 ~Cookie ()
 Destroys this Cookie object.
bool operator!= (const Cookie &other) const
 Returns true if this cookie is not equal to other.
Cookieoperator= (const Cookie &other)
 Copies the contents of the Cookie object other to this object.
Cookieoperator= (Cookie &&other) noexcept
 Move assigns the contents of the Cookie object other to this object.
bool operator== (const Cookie &other) const
 Returns true if this cookie is equal to other.
SameSite sameSitePolicy () const
 Returns the "SameSite" option if specified in the cookie string, SameSite::Default if not present.
void setSameSitePolicy (SameSite sameSite)
 Sets the "SameSite" option of this cookie to sameSite.
void swap (Cookie &other) noexcept
 Swaps this cookie with other.
QByteArray toRawForm (RawForm form=Full) const
 Returns the raw form of this Cookie.
Public Member Functions inherited from QNetworkCookie
 QNetworkCookie (const QByteArray &name, const QByteArray &value)
 QNetworkCookie (const QNetworkCookie &other)
QString domain () const const
QDateTime expirationDate () const const
bool hasSameIdentifier (const QNetworkCookie &other) const const
bool isHttpOnly () const const
bool isSecure () const const
bool isSessionCookie () const const
QByteArray name () const const
void normalize (const QUrl &url)
bool operator!= (const QNetworkCookie &other) const const
QNetworkCookieoperator= (const QNetworkCookie &other)
bool operator== (const QNetworkCookie &other) const const
QString path () const const
void setDomain (const QString &domain)
void setExpirationDate (const QDateTime &date)
void setHttpOnly (bool enable)
void setName (const QByteArray &cookieName)
void setPath (const QString &path)
void setSecure (bool enable)
void setValue (const QByteArray &value)
void swap (QNetworkCookie &other)
QByteArray toRawForm (RawForm form) const const
QByteArray value () const const

Additional Inherited Members

Static Public Member Functions inherited from QNetworkCookie
QList< QNetworkCookieparseCookies (const QByteArray &cookieString)
Public Attributes inherited from QNetworkCookie
 Full
 NameAndValueOnly

Detailed Description

This is an extension of QNetworkCookie that adds support for the SameSite property. QNetworkCookie added support for the SameSite property in Qt 6.1. So, if you are only using Qt 6.1 or newer, please use QNetworkCookie and the methods that take it as argument instead.

Since
Cutelyst 3.8.0

Definition at line 28 of file cookie.h.

Member Enumeration Documentation

◆ SameSite

enum class Cutelyst::Cookie::SameSite
strong
Enumerator
Default 

SameSite is not set. Can be interpreted as None or Lax by the browser.

None 

Cookies can be sent in all contexts. This used to be default, but recent browsers made Lax default, and will now require the cookie to be both secure and to set SameSite=None.

Lax 

Cookies are sent on first party requests and GET requests initiated by third party website. This is the default in modern browsers (since mid 2020).

Strict 

Cookies will only be sent in a first-party context.

Definition at line 32 of file cookie.h.

Constructor & Destructor Documentation

◆ Cookie() [1/2]

Cookie::Cookie ( const QByteArray & name = QByteArray(),
const QByteArray & value = QByteArray() )
explicit

A cookie is only valid if it has a name. However, the value is opaque to the application and being empty may have significance to the remote server.

Definition at line 15 of file cookie.cpp.

References QNetworkCookie::QNetworkCookie(), QNetworkCookie::name(), and QNetworkCookie::value().

Referenced by Cookie(), operator!=(), operator=(), operator=(), operator==(), and swap().

◆ Cookie() [2/2]

Cookie::Cookie ( const Cookie & other)

Definition at line 23 of file cookie.cpp.

References Cookie(), and QNetworkCookie::QNetworkCookie().

Member Function Documentation

◆ operator!=()

bool Cutelyst::Cookie::operator!= ( const Cookie & other) const
inline

Definition at line 91 of file cookie.h.

References Cookie().

◆ operator=() [1/2]

Cookie & Cookie::operator= ( const Cookie & other)

Definition at line 31 of file cookie.cpp.

References Cookie(), and QNetworkCookie::operator=().

◆ operator=() [2/2]

Cookie & Cutelyst::Cookie::operator= ( Cookie && other)
inlinenoexcept

Definition at line 62 of file cookie.h.

References Cookie(), and swap().

◆ operator==()

bool Cookie::operator== ( const Cookie & other) const

This function only returns true if all fields of the cookie are the same.

However, in some contexts, two cookies of the same name could be considered equal.

Definition at line 38 of file cookie.cpp.

References Cookie(), and QNetworkCookie::operator==().

◆ sameSitePolicy()

Cookie::SameSite Cookie::sameSitePolicy ( ) const

Definition at line 47 of file cookie.cpp.

◆ setSameSitePolicy()

void Cookie::setSameSitePolicy ( Cookie::SameSite sameSite)

Definition at line 52 of file cookie.cpp.

◆ swap()

void Cutelyst::Cookie::swap ( Cookie & other)
inlinenoexcept

This function is very fast and never fails.

Definition at line 75 of file cookie.h.

References Cookie(), and QNetworkCookie::swap().

Referenced by operator=().

◆ toRawForm()

QByteArray Cookie::toRawForm ( RawForm form = Full) const

The QByteArray returned by this function is suitable for an HTTP header, either in a server response (the Set-Cookie header) or the client request (the Cookie header). You can choose from one of two formats, using form.

Definition at line 74 of file cookie.cpp.

References QLocale::c(), Default, QNetworkCookie::domain(), QNetworkCookie::expirationDate(), QNetworkCookie::Full, QAbstractSocket::IPv6Protocol, QNetworkCookie::isHttpOnly(), QNetworkCookie::isSecure(), QNetworkCookie::isSessionCookie(), QNetworkCookie::name(), QNetworkCookie::path(), QHostAddress::protocol(), QUrl::toAce(), QString::toLatin1(), QLocale::toString(), QString::toUtf8(), and QNetworkCookie::value().