From 36059bfa36b97c3e599db1baa93bbdb948b689aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 2 Apr 2024 16:18:23 +0200 Subject: [PATCH] QHttp2Connection: fix handling of replies on locally initiated stream It was overlooked in testing, but it would emit a signal for new incoming stream even if the server was just replying with HEADERS on a stream the client had initiated. Or vice-versa. Change-Id: Ie7b3a45729a78106da1d8c058e15705cc7dcc53b Reviewed-by: Alexey Edelev (cherry picked from commit 1d03e1851bcaf80700f19c8c583e6b9abc2059a7) Reviewed-by: Qt Cherry-pick Bot --- src/network/access/qhttp2connection.cpp | 7 ++++++- .../access/qhttp2connection/tst_qhttp2connection.cpp | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/network/access/qhttp2connection.cpp b/src/network/access/qhttp2connection.cpp index 38b219ed175..0bad7481715 100644 --- a/src/network/access/qhttp2connection.cpp +++ b/src/network/access/qhttp2connection.cpp @@ -910,8 +910,13 @@ void QHttp2Connection::handleHEADERS() if (streamID == connectionStreamID) return connectionError(PROTOCOL_ERROR, "HEADERS on 0x0 stream"); - if (streamID > m_lastIncomingStreamID) { + const bool isClient = m_connectionType == Type::Client; + const bool isClientInitiatedStream = !!(streamID & 1); + const bool isRemotelyInitiatedStream = isClient ^ isClientInitiatedStream; + + if (isRemotelyInitiatedStream && streamID > m_lastIncomingStreamID) { QHttp2Stream *newStream = createStreamInternal_impl(streamID); + Q_ASSERT(newStream); m_lastIncomingStreamID = streamID; qCDebug(qHttp2ConnectionLog, "[%p] Created new incoming stream %d", this, streamID); emit newIncomingStream(newStream); diff --git a/tests/auto/network/access/qhttp2connection/tst_qhttp2connection.cpp b/tests/auto/network/access/qhttp2connection/tst_qhttp2connection.cpp index d9641c7391d..cfb51b0e300 100644 --- a/tests/auto/network/access/qhttp2connection/tst_qhttp2connection.cpp +++ b/tests/auto/network/access/qhttp2connection/tst_qhttp2connection.cpp @@ -266,6 +266,7 @@ void tst_QHttp2Connection::connectToServer() QVERIFY(waitForSettingsExchange(connection, serverConnection)); QSignalSpy newIncomingStreamSpy{ serverConnection, &QHttp2Connection::newIncomingStream }; + QSignalSpy clientIncomingStreamSpy{ connection, &QHttp2Connection::newIncomingStream }; QHttp2Stream *clientStream = connection->createStream().unwrap(); QSignalSpy clientHeaderReceivedSpy{ clientStream, &QHttp2Stream::headersReceived }; @@ -283,6 +284,8 @@ void tst_QHttp2Connection::connectToServer() const HPack::HttpHeader headersReceived = clientHeaderReceivedSpy.front().front().value(); QCOMPARE(headersReceived, ExpectedResponseHeaders); + + QCOMPARE(clientIncomingStreamSpy.count(), 0); } void tst_QHttp2Connection::WINDOW_UPDATE()