summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index 968f25fcf3..d6de1f98e5 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -380,6 +380,9 @@ private Q_SLOTS:
void qtbug18232gzipContentLengthZero();
void qtbug22660gzipNoContentLengthEmptyContent();
+ void qtbug27161httpHeaderMayBeDamaged_data();
+ void qtbug27161httpHeaderMayBeDamaged();
+
void synchronousRequest_data();
void synchronousRequest();
#ifndef QT_NO_SSL
@@ -6445,6 +6448,77 @@ void tst_QNetworkReply::qtbug22660gzipNoContentLengthEmptyContent()
QCOMPARE(reply->readAll(), QByteArray());
}
+class QtBug27161Helper : public QObject {
+ Q_OBJECT
+public:
+ QtBug27161Helper(MiniHttpServer & server, const QByteArray & data):
+ m_server(server),
+ m_data(data)
+ {
+ connect(&m_server, SIGNAL(newConnection()), this, SLOT(newConnectionSlot()));
+ }
+public slots:
+ void newConnectionSlot(){
+ connect(m_server.client, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot()));
+ }
+
+ void bytesWrittenSlot(){
+ disconnect(m_server.client, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot()));
+ m_Timer.singleShot(100, this, SLOT(timeoutSlot()));
+ }
+
+ void timeoutSlot(){
+ m_server.doClose = true;
+ // we need to emulate the bytesWrittenSlot call if the data is empty.
+ if (m_data.size() == 0)
+ QMetaObject::invokeMethod(&m_server, "bytesWrittenSlot", Qt::QueuedConnection);
+ else
+ m_server.client->write(m_data);
+ }
+
+private:
+ MiniHttpServer & m_server;
+ QByteArray m_data;
+ QTimer m_Timer;
+};
+
+void tst_QNetworkReply::qtbug27161httpHeaderMayBeDamaged_data(){
+ QByteArray response("HTTP/1.0 200 OK\r\nServer: bogus\r\nContent-Length: 3\r\n\r\nABC");
+ QTest::addColumn<QByteArray>("firstPacket");
+ QTest::addColumn<QByteArray>("secondPacket");
+
+ for (int i = 1; i < response.size(); i++){
+ QByteArray dataTag("Iteration: ");
+ dataTag.append(QByteArray::number(i - 1));
+ QTest::newRow(dataTag.constData()) << response.left(i) << response.mid(i);
+ }
+}
+
+/*
+ * Purpose of this test is to check whether a content from server is parsed correctly
+ * if it is splitted into two parts.
+ */
+void tst_QNetworkReply::qtbug27161httpHeaderMayBeDamaged(){
+ QFETCH(QByteArray, firstPacket);
+ QFETCH(QByteArray, secondPacket);
+ MiniHttpServer server(firstPacket);
+ server.doClose = false;
+ QtBug27161Helper helper(server, secondPacket);
+
+ QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort())));
+ QNetworkReplyPtr reply(manager.get(request));
+
+ QVERIFY(waitForFinish(reply) == Success);
+
+ QVERIFY(reply->isFinished());
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+ QCOMPARE(reply->size(), qint64(3));
+ QCOMPARE(reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(), qint64(3));
+ QCOMPARE(reply->rawHeader("Content-length"), QByteArray("3"));
+ QCOMPARE(reply->rawHeader("Server"), QByteArray("bogus"));
+ QCOMPARE(reply->readAll(), QByteArray("ABC"));
+}
+
void tst_QNetworkReply::synchronousRequest_data()
{
QTest::addColumn<QUrl>("url");