diff options
author | Yigit Akcay <yigit.akcay@qt.io> | 2023-02-15 20:43:25 +0100 |
---|---|---|
committer | Yigit Akcay <yigit.akcay@qt.io> | 2023-03-10 17:13:32 +0100 |
commit | 5e257fb57a211f95556ec387fe6f262a60cbb6fe (patch) | |
tree | 330abbb7f84f8664fbd44b80d573265da4cc2bcb /src/core/api/qwebengineurlresponseinfo.cpp | |
parent | 28a2cfe4116f7218b33df811b79536c0593ddda6 (diff) | |
download | qtwebengine-5e257fb57a211f95556ec387fe6f262a60cbb6fe.tar.gz |
QWebEngineUrlResponseInterceptor: Implement new URL response interceptor
This patch adds the QWebEngineUrlResponseInterceptor abstract class,
which, when implemented, allows a user to intercept response headers and
modify them in any way they like.
A response interceptor can be set via
QWebEngineProfile::setUrlResponseInterceptor(),
QQuickWebEngineProfile::setUrlResponseInterceptor() or
QWebEnginePage::setUrlResponseInterceptor().
Also, the QWebEngineUrlResponseInfo class is implemented, which contains
the request and response data to be used with the response interceptor.
If a response interceptor is set in the profile and page, the one in the
profile takes precedence.
Fixes: QTBUG-61071
Change-Id: I484d14373ff597b1d531541c066f0102bae28c72
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'src/core/api/qwebengineurlresponseinfo.cpp')
-rw-r--r-- | src/core/api/qwebengineurlresponseinfo.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/core/api/qwebengineurlresponseinfo.cpp b/src/core/api/qwebengineurlresponseinfo.cpp new file mode 100644 index 000000000..8ec1024da --- /dev/null +++ b/src/core/api/qwebengineurlresponseinfo.cpp @@ -0,0 +1,79 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#include "qwebengineurlresponseinfo.h" +#include "qwebengineurlresponseinfo_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QWebEngineUrlResponseInfo + \brief A utility type for the QWebEngineUrlResponseInterceptor. + \inmodule QtWebEngineCore + \since 6.6 + + Contains information about the request that has caused the response + intercepted by a QWebEngineUrlResponseInterceptor. + + \sa QWebEngineUrlResponseInterceptor +*/ +QWebEngineUrlResponseInfo::QWebEngineUrlResponseInfo( + const QUrl &requestUrl, const QHash<QByteArray, QByteArray> &requestHeaders, + const QHash<QByteArray, QByteArray> &responseHeaders, QObject *p) + : QObject(p) + , d_ptr(new QWebEngineUrlResponseInfoPrivate(requestUrl, requestHeaders, responseHeaders)) +{ +} + +/*! + \property QWebEngineUrlResponseInfo::requestUrl + \brief Holds the URL of the URL load request. +*/ +QUrl QWebEngineUrlResponseInfo::requestUrl() const +{ + Q_D(const QWebEngineUrlResponseInfo); + return d->requestUrl; +} + +/*! + \property QWebEngineUrlResponseInfo::requestHeaders + \brief Holds the request headers of the URL load request. +*/ +QHash<QByteArray, QByteArray> QWebEngineUrlResponseInfo::requestHeaders() const +{ + Q_D(const QWebEngineUrlResponseInfo); + return d->requestHeaders; +} + +/*! + \property QWebEngineUrlResponseInfo::responseHeaders + \brief Holds the response headers of the URL load request. +*/ +QHash<QByteArray, QByteArray> QWebEngineUrlResponseInfo::responseHeaders() const +{ + Q_D(const QWebEngineUrlResponseInfo); + return d->responseHeaders; +} + +/*! + \fn void QWebEngineUrlResponseInfo::setResponseHeaders( + const QHash<QByteArray, QByteArray> &newResponseHeaders) + \brief Sets the response headers to \a newResponseHeaders. + + Sets the response headers to \a newResponseHeaders. If \a newResponseHeaders + differ from the current response headers then + QWebEngineUrlResponseInfo::isModified() will now return \c true. +*/ +void QWebEngineUrlResponseInfo::setResponseHeaders( + const QHash<QByteArray, QByteArray> &newResponseHeaders) +{ + Q_D(QWebEngineUrlResponseInfo); + if (d->responseHeaders != newResponseHeaders) { + d->responseHeaders = newResponseHeaders; + d->isModified = true; + } +} + +QT_END_NAMESPACE + +#include "moc_qwebengineurlresponseinfo.cpp" |