8 using namespace stefanfrings;
18 const QByteArray comment,
const QByteArray domain,
const bool secure,
const bool httpOnly,
19 const QByteArray sameSite)
25 this->comment=comment;
28 this->httpOnly=httpOnly;
29 this->sameSite=sameSite;
39 QList<QByteArray> list=
splitCSV(source);
40 foreach(QByteArray part, list)
46 int posi=part.indexOf(
'=');
49 name=part.left(posi).trimmed();
50 value=part.mid(posi+1).trimmed();
63 else if (name==
"Domain")
67 else if (name==
"Max-Age")
71 else if (name==
"Path")
75 else if (name==
"Secure")
79 else if (name==
"HttpOnly")
83 else if (name==
"SameSite")
87 else if (name==
"Version")
89 version=value.toInt();
92 if (this->name.isEmpty())
99 qWarning(
"HttpCookie: Ignoring unknown %s=%s",name.data(),value.data());
107 QByteArray buffer(name);
109 buffer.append(value);
110 if (!comment.isEmpty())
112 buffer.append(
"; Comment=");
113 buffer.append(comment);
115 if (!domain.isEmpty())
117 buffer.append(
"; Domain=");
118 buffer.append(domain);
122 buffer.append(
"; Max-Age=");
123 buffer.append(QByteArray::number(maxAge));
127 buffer.append(
"; Path=");
131 buffer.append(
"; Secure");
134 buffer.append(
"; HttpOnly");
136 if (!sameSite.isEmpty()) {
137 buffer.append(
"; SameSite=");
138 buffer.append(sameSite);
140 buffer.append(
"; Version=");
141 buffer.append(QByteArray::number(version));
157 this->comment=comment;
182 this->httpOnly=httpOnly;
187 this->sameSite=sameSite;
243 QList<QByteArray> list;
245 for (
int i=0; i<source.size(); ++i)
256 QByteArray trimmed=buffer.trimmed();
257 if (!trimmed.isEmpty())
259 list.append(trimmed);
279 QByteArray trimmed=buffer.trimmed();
280 if (!trimmed.isEmpty())
282 list.append(trimmed);
QByteArray getValue() const
Get the value of this cookie.
void setName(const QByteArray name)
Set the name of this cookie.
bool getSecure() const
Get the secure flag of this cookie.
void setSameSite(const QByteArray sameSite)
Set same-site mode, so that the browser does not allow other web sites to access the cookie.
QByteArray getPath() const
Set the path of this cookie.
int getMaxAge() const
Get the maximum age of this cookie in seconds.
void setComment(const QByteArray comment)
Set the comment of this cookie.
void setValue(const QByteArray value)
Set the value of this cookie.
void setDomain(const QByteArray domain)
Set the domain of this cookie.
static QList< QByteArray > splitCSV(const QByteArray source)
Split a string list into parts, where each part is delimited by semicolon.
void setSecure(const bool secure)
Set secure mode, so that the cookie will be sent by the browser to the server only on secure connecti...
QByteArray getSameSite() const
Get the same-site flag of this cookie.
void setPath(const QByteArray path)
Set the path for that the cookie will be sent, default="/" which means the whole domain.
bool getHttpOnly() const
Get the HTTP-only flag of this cookie.
QByteArray getName() const
Get the name of this cookie.
int getVersion() const
Returns always 1.
HttpCookie()
Creates an empty cookie.
QByteArray getComment() const
Get the comment of this cookie.
void setMaxAge(const int maxAge)
Set the maximum age of this cookie in seconds.
void setHttpOnly(const bool httpOnly)
Set HTTP-only mode, so that the browser does not allow client-side scripts to access the cookie.
QByteArray getDomain() const
Get the domain of this cookie.
QByteArray toByteArray() const
Convert this cookie to a string that may be used in a Set-Cookie header.