summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/access/http2/http2srv.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/http2srv.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/http2srv.cpp')
-rw-r--r--tests/auto/network/access/http2/http2srv.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/tests/auto/network/access/http2/http2srv.cpp b/tests/auto/network/access/http2/http2srv.cpp
index 69e480b164..b0bae13bad 100644
--- a/tests/auto/network/access/http2/http2srv.cpp
+++ b/tests/auto/network/access/http2/http2srv.cpp
@@ -123,6 +123,12 @@ void Http2Server::emulateGOAWAY(int timeout)
goawayTimeout = timeout;
}
+void Http2Server::redirectOpenStream(quint16 port)
+{
+ redirectWhileReading = true;
+ targetPort = port;
+}
+
void Http2Server::startServer()
{
#ifdef QT_NO_SSL
@@ -775,7 +781,19 @@ void Http2Server::sendResponse(quint32 streamID, bool emptyBody)
if (emptyBody)
writer.addFlag(FrameFlag::END_STREAM);
- HttpHeader header = {{":status", "200"}};
+ HttpHeader header;
+ if (redirectWhileReading) {
+ qDebug("server received HEADERS frame (followed by DATA frames), redirecting ...");
+ Q_ASSERT(targetPort);
+ header.push_back({":status", "308"});
+ const QString url("%1://localhost:%2/");
+ header.push_back({"location", url.arg(clearTextHTTP2 ? QStringLiteral("http") : QStringLiteral("https"),
+ QString::number(targetPort)).toLatin1()});
+
+ } else {
+ header.push_back({":status", "200"});
+ }
+
if (!emptyBody) {
header.push_back(HPack::HeaderField("content-length",
QString("%1").arg(responseBody.size()).toLatin1()));
@@ -871,7 +889,13 @@ void Http2Server::processRequest()
activeRequests[streamID] = decoder.decodedHeader();
if (headersFrame.flags().testFlag(FrameFlag::END_STREAM))
emit receivedRequest(streamID);
- // else - we're waiting for incoming DATA frames ...
+
+ if (redirectWhileReading) {
+ sendResponse(streamID, true);
+ // Don't try to read any DATA frames ...
+ socket->disconnect();
+ } // else - we're waiting for incoming DATA frames ...
+
continuedRequest.clear();
}