From d8213cbff66784a3e1132e278d608500f88975f2 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Wed, 26 Oct 2011 14:45:50 +0100 Subject: HTTP proxy engine - accept standard Connection header The Proxy-Connection header is a non standard header, but is widely used so forming a de-facto standard. Some proxies use the official Connection header, so we should check for that in responses. Otherwise https connections over http proxy fail in case the proxy sends "Connection: close" with the 407 reply. Task-number: QTBUG-22177 Change-Id: If6cfa4ebb7ac9d97d65b6ddcc8257aee20ac0448 Reviewed-by: Peter Hartmann (cherry picked from commit 0ad18e18d1223b173d4a0d374b70ec08c3b22b11) --- src/network/socket/qhttpsocketengine.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp index 5c672ec..b62bc05 100644 --- a/src/network/socket/qhttpsocketengine.cpp +++ b/src/network/socket/qhttpsocketengine.cpp @@ -614,6 +614,10 @@ void QHttpSocketEngine::slotSocketReadNotification() bool willClose; QString proxyConnectionHeader = responseHeader.value(QLatin1String("Proxy-Connection")); + // Although most proxies use the unofficial Proxy-Connection header, the Connection header + // from http spec is also allowed. + if (proxyConnectionHeader.isEmpty()) + proxyConnectionHeader = responseHeader.value(QLatin1String("Connection")); proxyConnectionHeader = proxyConnectionHeader.toLower(); if (proxyConnectionHeader == QLatin1String("close")) { willClose = true; -- cgit v0.12 From 425272e7405eed077cb65a101d5dd1fafc4b11d2 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Thu, 10 Nov 2011 17:16:25 +0000 Subject: Fix warning when using QXmlInputSource with non opened QIODevice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling setTextModeEnabled on a QIODevice that is not open generates a warning as a result of QTBUG-20905. Previously, it caused incorrect behaviour when called with true. Now only call it if the QIODevice passed in is already opened. If not open, then it is opened by the xml reader without text mode, so there is no difference in behaviour. xml autotests still pass, although this removes several QWARN messages from the qdom autotest. Task-number: QTBUG-22659 Change-Id: Ie3137e44fe776bff6371ebd008428110168717ec Reviewed-by: João Abecasis (cherry picked from commit d457f148cf1efbea3db5fdc87c418cc9647e2baf) --- src/xml/sax/qxml.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/xml/sax/qxml.cpp b/src/xml/sax/qxml.cpp index 0c7f2ab..c4c5f0c 100644 --- a/src/xml/sax/qxml.cpp +++ b/src/xml/sax/qxml.cpp @@ -1321,7 +1321,8 @@ QXmlInputSource::QXmlInputSource(QIODevice *dev) { init(); d->inputDevice = dev; - d->inputDevice->setTextModeEnabled(false); + if (dev->isOpen()) + d->inputDevice->setTextModeEnabled(false); } #ifdef QT3_SUPPORT -- cgit v0.12 From 371617983a7640a42d74db9c17f7ac3c9c22d29d Mon Sep 17 00:00:00 2001 From: Sami Rosendahl Date: Fri, 11 Nov 2011 13:29:38 +0100 Subject: Fix crash in QHttpNetworkReplyPrivate::gunzipBodyPartiallyEnd If a HTTP server responds with gzip-encoded empty content without defining Content-Length in the response header QHttpNetworkReplyPrivate::gunzipBodyPartiallyEnd will crash because it calls zlib inflateEnd for an uninitialized stream. - Fixed the crash by adding a check if the stream is initialized to gunzipBodyPartiallyEnd. - Added a regression test tst_QNetworkReply::nb279420gzipNoContentLengthEmptyContentDisconnect PMO 279420 Task-number: QTBUG-22660 Signed-off-by: Sami Rosendahl Merge-request: 1465 Reviewed-by: Peter Hartmann --- src/network/access/qhttpnetworkreply.cpp | 6 ++++-- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index 6173b39..3dc8b2f 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -472,8 +472,10 @@ int QHttpNetworkReplyPrivate::gunzipBodyPartially(QByteArray &compressed, QByteA void QHttpNetworkReplyPrivate::gunzipBodyPartiallyEnd() { - inflateEnd(&inflateStrm); - initInflate = false; + if (initInflate) { + inflateEnd(&inflateStrm); + initInflate = false; + } } #endif diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 9df820a..14ad6a9 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -368,6 +368,7 @@ private Q_SLOTS: void qtbug15311doubleContentLength(); void qtbug18232gzipContentLengthZero(); + void nb279420gzipNoContentLengthEmptyContentDisconnect(); void synchronousRequest_data(); void synchronousRequest(); @@ -6139,6 +6140,28 @@ void tst_QNetworkReply::qtbug18232gzipContentLengthZero() QCOMPARE(reply->readAll(), QByteArray()); } +// Reproduced a crash in QHttpNetworkReplyPrivate::gunzipBodyPartiallyEnd +// where zlib inflateEnd was called for uninitialized zlib stream +void tst_QNetworkReply::nb279420gzipNoContentLengthEmptyContentDisconnect() +{ + // Response with no Content-Length in header and empty content + QByteArray response("HTTP/1.0 200 OK\r\nContent-Encoding: gzip\r\n\r\n"); + MiniHttpServer server(response); + server.doClose = true; + + QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); + QNetworkReplyPtr reply = manager.get(request); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(reply->isFinished()); + QCOMPARE(reply->error(), QNetworkReply::NoError); + QCOMPARE(reply->size(), qint64(0)); + QVERIFY(!reply->header(QNetworkRequest::ContentLengthHeader).isValid()); + QCOMPARE(reply->readAll(), QByteArray()); +} + void tst_QNetworkReply::synchronousRequest_data() { QTest::addColumn("url"); -- cgit v0.12