summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-12-22 06:12:26 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-12-22 06:12:26 (GMT)
commite50a0ad18c40322ca0c06a11e7dc7b9a82951f16 (patch)
treea3cf46174d036a3a5d8077dd1ef9e92301e44911
parent2d4d125313d79fb80f513952bed675b7126392fd (diff)
downloadQt-e50a0ad18c40322ca0c06a11e7dc7b9a82951f16.zip
Qt-e50a0ad18c40322ca0c06a11e7dc7b9a82951f16.tar.gz
Qt-e50a0ad18c40322ca0c06a11e7dc7b9a82951f16.tar.bz2
XmlListModel requests should set 'Accept' header to 'application/xml'
Task-number: QTBUG-15836 Reviewed-by: Michael Brasser
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp1
-rw-r--r--tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp69
2 files changed, 70 insertions, 0 deletions
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index 49a12b1..e97cd67 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -924,6 +924,7 @@ void QDeclarativeXmlListModel::reload()
} else {
d->notifyQueryStarted(true);
QNetworkRequest req(d->src);
+ req.setRawHeader("Accept", "application/xml");
d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req);
QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(requestFinished()));
QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)),
diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
index a14f942..b95b053 100644
--- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
@@ -38,8 +38,13 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <private/qdeclarativeengine_p.h>
+
#include <qtest.h>
#include <QtTest/qsignalspy.h>
+#include <QtDeclarative/qdeclarativenetworkaccessmanagerfactory.h>
+#include <QtNetwork/qnetworkaccessmanager.h>
+#include <QtNetwork/qnetworkrequest.h>
#include <QtCore/qtimer.h>
#include <QtCore/qfile.h>
#include <QtCore/qtemporaryfile.h>
@@ -81,6 +86,7 @@ private slots:
void roles();
void roleErrors();
void uniqueRoleNames();
+ void headers();
void xml();
void xml_data();
void source();
@@ -139,6 +145,44 @@ private:
QDeclarativeEngine engine;
};
+class CustomNetworkAccessManagerFactory : public QObject, public QDeclarativeNetworkAccessManagerFactory
+{
+ Q_OBJECT
+public:
+ QVariantMap lastSentHeaders;
+
+protected:
+ QNetworkAccessManager *create(QObject *parent);
+};
+
+class CustomNetworkAccessManager : public QNetworkAccessManager
+{
+ Q_OBJECT
+public:
+ CustomNetworkAccessManager(CustomNetworkAccessManagerFactory *factory, QObject *parent)
+ : QNetworkAccessManager(parent), m_factory(factory) {}
+
+protected:
+ QNetworkReply *createRequest(Operation op, const QNetworkRequest &req, QIODevice * outgoingData = 0)
+ {
+ if (m_factory) {
+ QVariantMap map;
+ foreach (const QString &header, req.rawHeaderList())
+ map[header] = req.rawHeader(header.toUtf8());
+ m_factory->lastSentHeaders = map;
+ }
+ return QNetworkAccessManager::createRequest(op, req, outgoingData);
+ }
+
+ QPointer<CustomNetworkAccessManagerFactory> m_factory;
+};
+
+QNetworkAccessManager *CustomNetworkAccessManagerFactory::create(QObject *parent)
+{
+ return new CustomNetworkAccessManager(this, parent);
+}
+
+
void tst_qdeclarativexmllistmodel::buildModel()
{
QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
@@ -312,6 +356,31 @@ void tst_qdeclarativexmllistmodel::xml_data()
QTest::newRow("one item") << "<Pets><Pet><name>Hobbes</name><type>Tiger</type><age>7</age><size>Large</size></Pet></Pets>" << 1;
}
+void tst_qdeclarativexmllistmodel::headers()
+{
+ // ensure the QNetworkAccessManagers created for this test are immediately deleted
+ QDeclarativeEngine qmlEng;
+
+ CustomNetworkAccessManagerFactory factory;
+ qmlEng.setNetworkAccessManagerFactory(&factory);
+
+ QDeclarativeComponent component(&qmlEng, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+ QTRY_COMPARE(model->status(), QDeclarativeXmlListModel::Ready);
+
+ QVariantMap expectedHeaders;
+ expectedHeaders["Accept"] = "application/xml";
+
+ QCOMPARE(factory.lastSentHeaders.count(), expectedHeaders.count());
+ foreach (const QString &header, expectedHeaders.keys()) {
+ QVERIFY(factory.lastSentHeaders.contains(header));
+ QCOMPARE(factory.lastSentHeaders[header].toString(), expectedHeaders[header].toString());
+ }
+
+ delete model;
+}
+
void tst_qdeclarativexmllistmodel::source()
{
QFETCH(QUrl, source);