diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-08-12 09:38:44 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-08-12 09:47:16 +0200 |
commit | 0d70ea37f83cb5a8caf63cbcebb30ddc48803190 (patch) | |
tree | cd57a626a4a9487ccca922d654ad3159662a0743 /tests/auto/shared | |
parent | 0c278cc00aaa95948f74ebabd2f6279ce0ea89e9 (diff) |
TestHTTPServer: Allow matching of header prefixes only
Sometimes we're not interested in the exact specifics of an HTTP header,
but we still want to accept it.
Change-Id: Id580f4a17c92afc3c7b6737633858aa5e385019a
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/shared')
-rw-r--r-- | tests/auto/shared/testhttpserver.cpp | 19 | ||||
-rw-r--r-- | tests/auto/shared/testhttpserver.h | 3 |
2 files changed, 17 insertions, 5 deletions
diff --git a/tests/auto/shared/testhttpserver.cpp b/tests/auto/shared/testhttpserver.cpp index f0d5a89984..6334ef9ddc 100644 --- a/tests/auto/shared/testhttpserver.cpp +++ b/tests/auto/shared/testhttpserver.cpp @@ -182,9 +182,11 @@ bool TestHTTPServer::wait(const QUrl &expect, const QUrl &reply, const QUrl &bod } if (headers_done) { m_waitData.body.append(line); + } else if (line.endsWith("{{Ignore}}\n")) { + m_waitData.headerPrefixes.append(line.left(line.length() - strlen("{{Ignore}}\n"))); } else { line.replace("{{ServerHostUrl}}", serverHostUrl); - m_waitData.headers.append(line); + m_waitData.headerExactMatches.append(line); } } /* @@ -257,7 +259,7 @@ void TestHTTPServer::readyRead() return; } - if (m_state == Failed || (m_waitData.body.isEmpty() && m_waitData.headers.count() == 0)) { + if (m_state == Failed || (m_waitData.body.isEmpty() && m_waitData.headerExactMatches.count() == 0)) { qWarning() << "TestHTTPServer: Unexpected data" << socket->readAll(); return; } @@ -271,9 +273,18 @@ void TestHTTPServer::readyRead() m_data += socket->readAll(); break; } else { - if (!m_waitData.headers.contains(line)) { + bool prefixFound = false; + for (const QByteArray &prefix : m_waitData.headerPrefixes) { + if (line.startsWith(prefix)) { + prefixFound = true; + break; + } + } + + if (!prefixFound && !m_waitData.headerExactMatches.contains(line)) { qWarning() << "TestHTTPServer: Unexpected header:" << line - << "\nExpected headers: " << m_waitData.headers; + << "\nExpected exact headers: " << m_waitData.headerExactMatches + << "\nExpected header prefixes: " << m_waitData.headerPrefixes; m_state = Failed; socket->disconnectFromHost(); return; diff --git a/tests/auto/shared/testhttpserver.h b/tests/auto/shared/testhttpserver.h index 2fd9ffba7d..4f537e3c4f 100644 --- a/tests/auto/shared/testhttpserver.h +++ b/tests/auto/shared/testhttpserver.h @@ -85,7 +85,8 @@ private: QSet<QString> m_contentSubstitutedFileNames; struct WaitData { - QList <QByteArray>headers; + QList<QByteArray> headerExactMatches; + QList<QByteArray> headerPrefixes; QByteArray body; } m_waitData; QByteArray m_replyData; |