From db5b8bbea3f3cf1675d2ddd449359b6fbedc523e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 9 Feb 2022 17:40:48 +0100 Subject: Http2: Fix redirect-handling The redirect handling for http2 was a little simple. E.g. not handling relative URLs. Fix this using the redirect response parsing function which the http1 protocol handler already uses. Fixes: QTBUG-100651 Pick-to: 6.3 6.2 5.15 Change-Id: Ic0cec4cacc92707e7a7fde1f4665f80995a6057e Reviewed-by: Qt CI Bot Reviewed-by: Timur Pocheptsov --- tests/auto/network/access/http2/http2srv.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests/auto/network/access/http2/http2srv.cpp') diff --git a/tests/auto/network/access/http2/http2srv.cpp b/tests/auto/network/access/http2/http2srv.cpp index 8a4917049e..27c7b47eda 100644 --- a/tests/auto/network/access/http2/http2srv.cpp +++ b/tests/auto/network/access/http2/http2srv.cpp @@ -130,6 +130,12 @@ void Http2Server::setAuthenticationHeader(const QByteArray &authentication) authenticationHeader = authentication; } +void Http2Server::setRedirect(const QByteArray &url, int count) +{ + redirectUrl = url; + redirectCount = count; +} + void Http2Server::emulateGOAWAY(int timeout) { Q_ASSERT(timeout >= 0); @@ -860,7 +866,10 @@ void Http2Server::sendResponse(quint32 streamID, bool emptyBody) const QString url("%1://localhost:%2/"); header.push_back({"location", url.arg(isClearText() ? QStringLiteral("http") : QStringLiteral("https"), QString::number(targetPort)).toLatin1()}); - + } else if (redirectCount > 0) { // Not redirecting while reading, unlike above + --redirectCount; + header.push_back({":status", "308"}); + header.push_back({"location", redirectUrl}); } else if (!authenticationHeader.isEmpty() && !hasAuth) { header.push_back({ ":status", "401" }); header.push_back(HPack::HeaderField("www-authenticate", authenticationHeader)); -- cgit v1.2.3