cutelyst 3.9.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Public Types | Public Member Functions | List of all members
Cutelyst::Cookie Class Reference

The Cutelyst Cookie. More...

#include <Cutelyst/Cookie>

Inheritance diagram for Cutelyst::Cookie:
Inheritance graph
[legend]

Public Types

enum class  SameSite { Default , None , Lax , Strict }
 

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.
 

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.

◆ Cookie() [2/2]

Cookie::Cookie ( const Cookie other)

Definition at line 23 of file cookie.cpp.

Member Function Documentation

◆ operator!=()

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

Definition at line 91 of file cookie.h.

◆ operator=() [1/2]

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

Definition at line 31 of file cookie.cpp.

◆ operator=() [2/2]

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

Definition at line 62 of file cookie.h.

◆ 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.

◆ 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.

◆ 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 Default.