summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/network/access/qnetworkrequest.cpp30
-rw-r--r--src/network/access/qnetworkrequest.h3
-rw-r--r--src/network/access/qnetworkrequest_p.h2
-rw-r--r--tests/auto/qnetworkrequest/tst_qnetworkrequest.cpp16
4 files changed, 51 insertions, 0 deletions
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index cde9858..ca9e606 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -481,6 +481,36 @@ void QNetworkRequest::setSslConfiguration(const QSslConfiguration &config)
}
#endif
+/*!
+ \since 4.6
+
+ Allows setting a reference to the object initiating
+ the request.
+
+ For example QtWebKit sets the originating object to the
+ QWebFrame that initiated the request.
+
+ \sa originatingObject()
+*/
+void QNetworkRequest::setOriginatingObject(QObject *object)
+{
+ d->originatingObject = object;
+}
+
+/*!
+ \since 4.6
+
+ Returns a reference to the object that initiated this
+ network request; returns 0 if not set or the object has
+ been destroyed.
+
+ \sa setOriginatingObject()
+*/
+QObject *QNetworkRequest::originatingObject() const
+{
+ return d->originatingObject.data();
+}
+
static QByteArray headerName(QNetworkRequest::KnownHeaders header)
{
switch (header) {
diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h
index 7b15237..62c6dda 100644
--- a/src/network/access/qnetworkrequest.h
+++ b/src/network/access/qnetworkrequest.h
@@ -120,6 +120,9 @@ public:
void setSslConfiguration(const QSslConfiguration &configuration);
#endif
+ void setOriginatingObject(QObject *object);
+ QObject *originatingObject() const;
+
private:
QSharedDataPointer<QNetworkRequestPrivate> d;
friend class QNetworkRequestPrivate;
diff --git a/src/network/access/qnetworkrequest_p.h b/src/network/access/qnetworkrequest_p.h
index 22b239f..9b3632f 100644
--- a/src/network/access/qnetworkrequest_p.h
+++ b/src/network/access/qnetworkrequest_p.h
@@ -58,6 +58,7 @@
#include "QtCore/qlist.h"
#include "QtCore/qhash.h"
#include "QtCore/qshareddata.h"
+#include "QtCore/qsharedpointer.h"
QT_BEGIN_NAMESPACE
@@ -73,6 +74,7 @@ public:
RawHeadersList rawHeaders;
CookedHeadersMap cookedHeaders;
AttributesMap attributes;
+ QWeakPointer<QObject> originatingObject;
RawHeadersList::ConstIterator findRawHeader(const QByteArray &key) const;
QList<QByteArray> rawHeadersKeys() const;
diff --git a/tests/auto/qnetworkrequest/tst_qnetworkrequest.cpp b/tests/auto/qnetworkrequest/tst_qnetworkrequest.cpp
index 3f9632c..2e21087 100644
--- a/tests/auto/qnetworkrequest/tst_qnetworkrequest.cpp
+++ b/tests/auto/qnetworkrequest/tst_qnetworkrequest.cpp
@@ -66,6 +66,7 @@ private slots:
void setHeader();
void rawHeaderParsing_data();
void rawHeaderParsing();
+ void originatingObject();
void removeHeader();
};
@@ -476,5 +477,20 @@ void tst_QNetworkRequest::removeHeader()
QVERIFY(request.hasRawHeader("bar"));
}
+void tst_QNetworkRequest::originatingObject()
+{
+ QNetworkRequest request;
+
+ QVERIFY(!request.originatingObject());
+
+ {
+ QObject dummy;
+ request.setOriginatingObject(&dummy);
+ QCOMPARE(request.originatingObject(), &dummy);
+ }
+
+ QVERIFY(!request.originatingObject());
+}
+
QTEST_MAIN(tst_QNetworkRequest)
#include "tst_qnetworkrequest.moc"