PySide6.QtNetwork.QNetworkCookieJar¶
- class QNetworkCookieJar¶
- The - QNetworkCookieJarclass implements a simple jar of- QNetworkCookieobjects. More…- Synopsis¶- Methods¶- def - __init__()
- def - allCookies()
- def - setAllCookies()
 - Virtual methods¶- def - cookiesForUrl()
- def - deleteCookie()
- def - insertCookie()
- def - updateCookie()
- def - validateCookie()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- 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. - QNetworkCookieJardoes not implement permanent storage: it only keeps the cookies in memory. Once the- QNetworkCookieJarobject 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- QNetworkReplyand- QNetworkAccessManagerwhen they detect new cookies and when they require cookies.- Creates a - QNetworkCookieJarobject and sets the parent object to be- parent.- The cookie jar is initialized to empty. - allCookies()¶
- Return type:
- .list of QNetworkCookie 
 
 - 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 - cookiesForUrl(url)¶
- Parameters:
- url – - QUrl
- Return type:
- .list of QNetworkCookie 
 
 - Returns the cookies to be added to when a request is sent to - url. This function is called by the default- 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 - QNetworkCookieJarclass 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 - deleteCookie(cookie)¶
- Parameters:
- cookie – - QNetworkCookie
- Return type:
- bool 
 
 - Deletes from cookie jar the cookie found to have the same identifier as - cookie.- Returns - trueif a cookie was deleted, false otherwise.- See also - insertCookie(cookie)¶
- Parameters:
- cookie – - QNetworkCookie
- Return type:
- bool 
 
 - Adds - cookieto this cookie jar.- Returns - trueif- cookiewas added, false otherwise.- If a cookie with the same identifier already exists in the cookie jar, it will be overridden. - setAllCookies(cookieList)¶
- Parameters:
- cookieList – .list of QNetworkCookie 
 
 - 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 - setCookiesFromUrl(cookieList, url)¶
- Parameters:
- cookieList – .list of QNetworkCookie 
- url – - QUrl
 
- Return type:
- bool 
 
 - Adds the cookies in the list - cookieListto this cookie jar. Before being inserted cookies are normalized.- Returns - trueif 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 - QNetworkCookieJarclass 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().- Also, - QNetworkCookieJardoes not have a maximum cookie jar size. Reimplement this function to discard older cookies to create room for new ones.- See also - updateCookie(cookie)¶
- Parameters:
- cookie – - QNetworkCookie
- Return type:
- bool 
 
 - If a cookie with the same identifier as - cookieexists in this cookie jar it will be updated. This function uses- insertCookie().- Returns - trueif- cookiewas updated, false if no cookie in the jar matches the identifier of- cookie.- See also - validateCookie(cookie, url)¶
- Parameters:
- cookie – - QNetworkCookie
- url – - QUrl
 
- Return type:
- bool 
 
 - Returns - trueif the domain and path of- cookieare valid, false otherwise. The- urlparameter is used to determine if the domain specified in the cookie is allowed.