aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/cookieinterceptor.cpp
blob: 88cc4759318bf7aef446607dd01416af095b85a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
 * This file is part of smolbote. It's copyrighted by the contributors recorded
 * in the version control history of the file, available from its original
 * location: git://neueland.iserlohn-fortress.net/smolbote.git
 *
 * SPDX-License-Identifier: GPL-3.0
 */

#include "cookieinterceptor.h"
#include <QDateTime>
#include <QWebEngineCookieStore>

CookieInterceptor::CookieInterceptor(const QString &path, QObject *parent)
    : QObject(parent)
{
}

void CookieInterceptor::judgeCookie(const QNetworkCookie &cookie) {
    QWebEngineCookieStore *store = dynamic_cast<QWebEngineCookieStore *>(sender());
    Q_CHECK_PTR(store);

    qDebug("Added cookie %s::%s", qUtf8Printable(cookie.domain()), qUtf8Printable(cookie.name()));

    // A session cookie is a cookie which has no expiration date, which means it should be discarded when
    // the application's concept of session is over (usually, when the application exits)
    if(!cookie.isSessionCookie()) {
        QNetworkCookie copyCookie(cookie);
        copyCookie.setExpirationDate(QDateTime::fromString(""));
        qDebug("cookie is now session?: %s", copyCookie.isSessionCookie() ? "yes" : "no");

        store->deleteCookie(cookie, cookie.domain());
        store->setCookie(copyCookie, copyCookie.domain());
    }
}