Example #1
0
String cookies(const Document* document, const KURL& url)
{
    QUrl u(url);
#if QT_VERSION >= 0x040400
    QNetworkCookieJar* jar = cookieJar(document);
    if (!jar)
        return String();

    QList<QNetworkCookie> cookies = jar->cookiesForUrl(u);
    if (cookies.isEmpty())
        return String();

    QStringList resultCookies;
    foreach (QNetworkCookie networkCookie, cookies) {
#if QT_VERSION >= 0x040500
        if (networkCookie.isHttpOnly())
            continue;
#endif
        resultCookies.append(QString::fromAscii(
                             networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));
    }

    return resultCookies.join(QLatin1String("; "));
#else
    QString cookies = QCookieJar::cookieJar()->cookies(u);
    int idx = cookies.indexOf(QLatin1Char(';'));
    if (idx > 0)
        cookies = cookies.left(idx);
    return cookies;
#endif
}