summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/access/http2/tst_http2.cpp
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2018-04-05 15:51:36 +0200
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2018-04-12 14:02:20 +0000
commit9917eb2ec69c2d5cc1db408660df43af34fe63fb (patch)
tree3285c2425ceaa6c4801a5da031221298ab030be2 /tests/auto/network/access/http2/tst_http2.cpp
parent144ee494b774fdc0fcdfdda53ebd8d4807a270dc (diff)
HTTP/2 - reset uploadByteDevice if necessary
1. If a request was redirected or some error was encountered, we try to reset the uploading byte-device. 2. Disconnecting from the byte-device is not enough, since we have a queued connection, _q_uploadDataReadyRead() gets called even if byte-device was deleted and thus sender() can return null - we have to check this condition. 3. Update auto-test with a case where our server immediately replies with a redirect status code. Task-number: QTBUG-67469 Task-number: QTBUG-66913 Change-Id: I9b364cf3dee1717940ddbe50cba37c3398cc9c95 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/network/access/http2/tst_http2.cpp')
-rw-r--r--tests/auto/network/access/http2/tst_http2.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp
index 51e1849512..ecf4c5814a 100644
--- a/tests/auto/network/access/http2/tst_http2.cpp
+++ b/tests/auto/network/access/http2/tst_http2.cpp
@@ -74,6 +74,7 @@ private slots:
void pushPromise();
void goaway_data();
void goaway();
+ void earlyResponse();
protected slots:
// Slots to listen to our in-process server:
@@ -439,6 +440,47 @@ void tst_Http2::goaway()
QVERIFY(!serverGotSettingsACK);
}
+void tst_Http2::earlyResponse()
+{
+ // In this test we'd like to verify client side can handle HEADERS frame while
+ // its stream is in 'open' state. To achieve this, we send a POST request
+ // with some payload, so that the client is first sending HEADERS and then
+ // DATA frames without END_STREAM flag set yet (thus the stream is in Stream::open
+ // state). Upon receiving the client's HEADERS frame our server ('redirector')
+ // immediately (without trying to read any DATA frames) responds with status
+ // code 308. The client should properly handle this.
+
+ clearHTTP2State();
+
+ serverPort = 0;
+ nRequests = 1;
+
+ ServerPtr targetServer(newServer(defaultServerSettings));
+
+ QMetaObject::invokeMethod(targetServer.data(), "startServer", Qt::QueuedConnection);
+ runEventLoop();
+
+ QVERIFY(serverPort != 0);
+
+ const quint16 targetPort = serverPort;
+ serverPort = 0;
+
+ ServerPtr redirector(newServer(defaultServerSettings));
+ redirector->redirectOpenStream(targetPort);
+
+ QMetaObject::invokeMethod(redirector.data(), "startServer", Qt::QueuedConnection);
+ runEventLoop();
+
+ QVERIFY(serverPort);
+ sendRequest(1, QNetworkRequest::NormalPriority, {10000000, Qt::Uninitialized});
+
+ runEventLoop();
+
+ QVERIFY(nRequests == 0);
+ QVERIFY(prefaceOK);
+ QVERIFY(serverGotSettingsACK);
+}
+
void tst_Http2::serverStarted(quint16 port)
{
serverPort = port;
@@ -500,6 +542,7 @@ void tst_Http2::sendRequest(int streamNumber,
QNetworkRequest request(url);
request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, QVariant(true));
+ request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, QVariant(true));
request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain"));
request.setPriority(priority);
@@ -592,6 +635,10 @@ void tst_Http2::replyFinished()
const QVariant spdyUsed(reply->attribute(QNetworkRequest::SpdyWasUsedAttribute));
QVERIFY(spdyUsed.isValid());
QVERIFY(!spdyUsed.toBool());
+ const QVariant code(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute));
+ QVERIFY(code.isValid());
+ QVERIFY(code.canConvert<int>());
+ QCOMPARE(code.value<int>(), 200);
}
--nRequests;