1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QNETWORKCOOKIE_H
5#define QNETWORKCOOKIE_H
6
7#include <QtNetwork/qtnetworkglobal.h>
8#include <QtCore/QSharedDataPointer>
9#include <QtCore/QList>
10#include <QtCore/QMetaType>
11#include <QtCore/QObject>
12
13QT_BEGIN_NAMESPACE
14
15
16class QByteArray;
17class QDateTime;
18class QString;
19class QUrl;
20
21class QNetworkCookiePrivate;
22class Q_NETWORK_EXPORT QNetworkCookie
23{
24 Q_GADGET
25public:
26 enum RawForm {
27 NameAndValueOnly,
28 Full
29 };
30 enum class SameSite {
31 Default,
32 None,
33 Lax,
34 Strict
35 };
36 Q_ENUM(SameSite)
37
38 explicit QNetworkCookie(const QByteArray &name = QByteArray(), const QByteArray &value = QByteArray());
39 QNetworkCookie(const QNetworkCookie &other);
40 ~QNetworkCookie();
41 QNetworkCookie &operator=(QNetworkCookie &&other) noexcept { swap(other); return *this; }
42 QNetworkCookie &operator=(const QNetworkCookie &other);
43
44 void swap(QNetworkCookie &other) noexcept { d.swap(other&: other.d); }
45
46 bool operator==(const QNetworkCookie &other) const;
47 inline bool operator!=(const QNetworkCookie &other) const
48 { return !(*this == other); }
49
50 bool isSecure() const;
51 void setSecure(bool enable);
52 bool isHttpOnly() const;
53 void setHttpOnly(bool enable);
54 SameSite sameSitePolicy() const;
55 void setSameSitePolicy(SameSite sameSite);
56
57 bool isSessionCookie() const;
58 QDateTime expirationDate() const;
59 void setExpirationDate(const QDateTime &date);
60
61 QString domain() const;
62 void setDomain(const QString &domain);
63
64 QString path() const;
65 void setPath(const QString &path);
66
67 QByteArray name() const;
68 void setName(const QByteArray &cookieName);
69
70 QByteArray value() const;
71 void setValue(const QByteArray &value);
72
73 QByteArray toRawForm(RawForm form = Full) const;
74
75 bool hasSameIdentifier(const QNetworkCookie &other) const;
76 void normalize(const QUrl &url);
77
78 static QList<QNetworkCookie> parseCookies(const QByteArray &cookieString);
79
80private:
81 QSharedDataPointer<QNetworkCookiePrivate> d;
82 friend class QNetworkCookiePrivate;
83};
84
85Q_DECLARE_SHARED(QNetworkCookie)
86
87#ifndef QT_NO_DEBUG_STREAM
88class QDebug;
89Q_NETWORK_EXPORT QDebug operator<<(QDebug, const QNetworkCookie &);
90#endif
91
92QT_END_NAMESPACE
93
94QT_DECL_METATYPE_EXTERN(QNetworkCookie, Q_NETWORK_EXPORT)
95
96#endif
97

source code of qtbase/src/network/access/qnetworkcookie.h