CopperSpice API  1.7.2
QNetworkCookieJar Class Reference

Implements a simple jar of QNetworkCookie objects. More...

Inheritance diagram for QNetworkCookieJar:
QObject

Public Methods

 QNetworkCookieJar (QObject *parent=nullptr)
 
virtual ~QNetworkCookieJar ()
 
virtual QList< QNetworkCookiecookiesForUrl (const QUrl &url) const
 
virtual bool deleteCookie (const QNetworkCookie &cookie)
 
virtual bool insertCookie (const QNetworkCookie &cookie)
 
virtual bool setCookiesFromUrl (const QList< QNetworkCookie > &cookieList, const QUrl &url)
 
virtual bool updateCookie (const QNetworkCookie &cookie)
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &objName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Protected Methods

QList< QNetworkCookieallCookies () const
 
void setAllCookies (const QList< QNetworkCookie > &cookieList)
 
virtual bool validateCookie (const QNetworkCookie &cookie, const QUrl &url) const
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 
- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Properties inherited from QObject
 objectName
 

Detailed Description

The QNetworkCookieJar class implements a simple jar of QNetworkCookie objects. Cookies are small bits of information that stateless protocols like HTTP use to maintain some persistent information across requests. A cookie is set by a remote server when it replies to a request and it expects the same cookie to be sent back when further requests are sent.

The cookie jar is the object that holds all cookies set in previous requests. Web browsers save their cookie jars to disk in order to conserve permanent cookies across invocations of the application.

QNetworkCookieJar does not implement permanent storage: it only keeps the cookies in memory. Once the QNetworkCookieJar object is deleted, all cookies it held will be discarded as well. If you want to save the cookies, you should derive from this class and implement the saving to disk to your own storage format.

This class implements only the basic security recommended by the cookie specifications and does not implement any cookie acceptance policy (it accepts all cookies set by any requests). In order to override those rules, you should reimplement the cookiesForUrl() and setCookiesFromUrl() virtual functions. They are called by QNetworkReply and QNetworkAccessManager when they detect new cookies and when they require cookies.

See also
QNetworkCookie, QNetworkAccessManager, QNetworkReply, QNetworkRequest, QNetworkAccessManager::setCookieJar()

Constructor & Destructor Documentation

QNetworkCookieJar::QNetworkCookieJar ( QObject parent = nullptr)

Creates a QNetworkCookieJar object and sets the parent object to be parent.

The cookie jar is initialized to empty.

QNetworkCookieJar::~QNetworkCookieJar ( )
virtual

Destroys this cookie jar object and discards all cookies stored in it. Cookies are not saved to disk in the QNetworkCookieJar default implementation.

If you need to save the cookies to disk, you have to derive from QNetworkCookieJar and save the cookies to disk yourself.

Method Documentation

QList< QNetworkCookie > QNetworkCookieJar::allCookies ( ) const
protected

Returns all cookies stored in this cookie jar. This function is suitable for derived classes to save cookies to disk, as well as to implement cookie expiration and other policies.

See also
setAllCookies(), cookiesForUrl()
QList< QNetworkCookie > QNetworkCookieJar::cookiesForUrl ( const QUrl url) const
virtual

Returns the cookies to be added to when a request is sent to url. This function is called by the default QNetworkAccessManager::createRequest(), which adds the cookies returned by this function to the request being sent.

If more than one cookie with the same name is found, but with differing paths, the one with longer path is returned before the one with shorter path. In other words, this function returns cookies sorted decreasingly by path length.

The default QNetworkCookieJar class implements only a very basic security policy (it makes sure that the cookies' domain and path match the reply's). To enhance the security policy with your own algorithms, override cookiesForUrl().

See also
setCookiesFromUrl(), QNetworkAccessManager::setCookieJar()
bool QNetworkCookieJar::deleteCookie ( const QNetworkCookie cookie)
virtual

Deletes from cookie jar the cookie found to have the same identifier as cookie. Returns true if a cookie was deleted, false otherwise.

See also
QNetworkCookie::hasSameIdentifier()
bool QNetworkCookieJar::insertCookie ( const QNetworkCookie cookie)
virtual

Adds cookie to this cookie jar. Returns true if cookie was added, false otherwise. If a cookie with the same identifier already exists in the cookie jar, it will be overridden.

Adds cookie to this cookie jar. Returns true if cookie was added, false otherwise.

If a cookie with the same identifier already exists in the cookie jar, it will be overridden.

void QNetworkCookieJar::setAllCookies ( const QList< QNetworkCookie > &  cookieList)
protected

Sets the internal list of cookies held by this cookie jar to be cookieList. This function is suitable for derived classes to implement loading cookies from permanent storage, or their own cookie acceptance policies by reimplementing setCookiesFromUrl().

See also
allCookies(), setCookiesFromUrl()
bool QNetworkCookieJar::setCookiesFromUrl ( const QList< QNetworkCookie > &  cookieList,
const QUrl url 
)
virtual

Adds the cookies in the list cookieList to this cookie jar. Default values for path and domain are taken from the url object. Returns true if one or more cookies are set for url, otherwise false. If a cookie already exists in the cookie jar, it will be overridden by those in cookieList.

The default QNetworkCookieJar class implements only a very basic security policy (it makes sure that the cookies' domain and path match the reply's). To enhance the security policy with your own algorithms, override setCookiesFromUrl().

QNetworkCookieJar does not have a maximum cookie jar size. Reimplement this function to discard older cookies to create room for new ones.

See also
cookiesForUrl(), QNetworkAccessManager::setCookieJar()
bool QNetworkCookieJar::updateCookie ( const QNetworkCookie cookie)
virtual

If a cookie with the same identifier as cookie exists in this cookie jar it will be updated. This function uses insertCookie(). Returns true if cookie was updated, false if no cookie in the jar matches the identifier of cookie.

See also
QNetworkCookie::hasSameIdentifier()
bool QNetworkCookieJar::validateCookie ( const QNetworkCookie cookie,
const QUrl url 
) const
protectedvirtual

Returns true if the domain and path of cookie are valid, false otherwise. The url parameter is used to determine if the domain specified in the cookie is allowed.