QtWebApp
stefanfrings::HttpCookie Class Reference

HTTP cookie as defined in RFC 2109. More...

#include <httpcookie.h>

Public Member Functions

 HttpCookie ()
 Creates an empty cookie.
 
 HttpCookie (const QByteArray name, const QByteArray value, const int maxAge, const QByteArray path="/", const QByteArray comment=QByteArray(), const QByteArray domain=QByteArray(), const bool secure=false, const bool httpOnly=false, const QByteArray sameSite=QByteArray())
 Create a cookie and set name/value pair. More...
 
 HttpCookie (const QByteArray source)
 Create a cookie from a string. More...
 
QByteArray toByteArray () const
 Convert this cookie to a string that may be used in a Set-Cookie header.
 
void setName (const QByteArray name)
 Set the name of this cookie.
 
void setValue (const QByteArray value)
 Set the value of this cookie.
 
void setComment (const QByteArray comment)
 Set the comment of this cookie.
 
void setDomain (const QByteArray domain)
 Set the domain of this cookie.
 
void setMaxAge (const int maxAge)
 Set the maximum age of this cookie in seconds. More...
 
void setPath (const QByteArray path)
 Set the path for that the cookie will be sent, default="/" which means the whole domain.
 
void setSecure (const bool secure)
 Set secure mode, so that the cookie will be sent by the browser to the server only on secure connections.
 
void setHttpOnly (const bool httpOnly)
 Set HTTP-only mode, so that the browser does not allow client-side scripts to access the cookie.
 
void setSameSite (const QByteArray sameSite)
 Set same-site mode, so that the browser does not allow other web sites to access the cookie. More...
 
QByteArray getName () const
 Get the name of this cookie.
 
QByteArray getValue () const
 Get the value of this cookie.
 
QByteArray getComment () const
 Get the comment of this cookie.
 
QByteArray getDomain () const
 Get the domain of this cookie.
 
int getMaxAge () const
 Get the maximum age of this cookie in seconds.
 
QByteArray getPath () const
 Set the path of this cookie.
 
bool getSecure () const
 Get the secure flag of this cookie.
 
bool getHttpOnly () const
 Get the HTTP-only flag of this cookie.
 
QByteArray getSameSite () const
 Get the same-site flag of this cookie.
 
int getVersion () const
 Returns always 1.
 

Static Public Member Functions

static QList< QByteArray > splitCSV (const QByteArray source)
 Split a string list into parts, where each part is delimited by semicolon. More...
 

Detailed Description

HTTP cookie as defined in RFC 2109.

Supports some additional attributes of RFC6265bis.

Definition at line 20 of file httpcookie.h.

Constructor & Destructor Documentation

◆ HttpCookie() [1/2]

HttpCookie::HttpCookie ( const QByteArray  name,
const QByteArray  value,
const int  maxAge,
const QByteArray  path = "/",
const QByteArray  comment = QByteArray(),
const QByteArray  domain = QByteArray(),
const bool  secure = false,
const bool  httpOnly = false,
const QByteArray  sameSite = QByteArray() 
)

Create a cookie and set name/value pair.

Parameters
namename of the cookie
valuevalue of the cookie
maxAgemaximum age of the cookie in seconds. 0=discard immediately
pathPath for that the cookie will be sent, default="/" which means the whole domain
commentOptional comment, may be displayed by the web browser somewhere
domainOptional domain for that the cookie will be sent. Defaults to the current domain
secureIf true, the cookie will be sent by the browser to the server only on secure connections
httpOnlyIf true, the browser does not allow client-side scripts to access the cookie
sameSiteDeclare if the cookie can only be read by the same site, which is a stronger restriction than the domain. Allowed values: "Lax" and "Strict".

Definition at line 17 of file httpcookie.cpp.

◆ HttpCookie() [2/2]

HttpCookie::HttpCookie ( const QByteArray  source)

Create a cookie from a string.

Parameters
sourceString as received in a HTTP Cookie2 header.

Definition at line 33 of file httpcookie.cpp.

Member Function Documentation

◆ setMaxAge()

void HttpCookie::setMaxAge ( const int  maxAge)

Set the maximum age of this cookie in seconds.

0=discard immediately

Definition at line 165 of file httpcookie.cpp.

◆ setSameSite()

void HttpCookie::setSameSite ( const QByteArray  sameSite)

Set same-site mode, so that the browser does not allow other web sites to access the cookie.

Allowed values: "Lax" and "Strict".

Definition at line 185 of file httpcookie.cpp.

◆ splitCSV()

QList< QByteArray > HttpCookie::splitCSV ( const QByteArray  source)
static

Split a string list into parts, where each part is delimited by semicolon.

Semicolons within double quotes are skipped. Double quotes are removed.

Definition at line 240 of file httpcookie.cpp.


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