summaryrefslogtreecommitdiffstats
path: root/src/network/access/qhttp2protocolhandler.cpp
diff options
context:
space:
mode:
authorAnton Kudryavtsev <anton.kudryavtsev@vk.team>2023-08-28 18:14:09 +0300
committerAnton Kudryavtsev <anton.kudryavtsev@vk.team>2023-09-25 17:17:56 +0300
commit0b512d7f41d501dd8e367ce7f3594c89f5c08702 (patch)
treea75e75a44b29f277a22335a8a48f249572c9b099 /src/network/access/qhttp2protocolhandler.cpp
parentcfa36a52ab58e8e0d4aa3d2af6d3095e1341f683 (diff)
QHttp2ProtocolHandler: extract method
for making url to improve readability Change-Id: I743f183b64f2ed9c9363ea4fd2bdb8588fd84547 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/network/access/qhttp2protocolhandler.cpp')
-rw-r--r--src/network/access/qhttp2protocolhandler.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp
index 90be29eea2..3ce4f2229a 100644
--- a/src/network/access/qhttp2protocolhandler.cpp
+++ b/src/network/access/qhttp2protocolhandler.cpp
@@ -26,6 +26,7 @@
#include <algorithm>
#include <vector>
+#include <optional>
QT_BEGIN_NAMESPACE
@@ -1472,30 +1473,27 @@ quint32 QHttp2ProtocolHandler::allocateStreamID()
return streamID;
}
-bool QHttp2ProtocolHandler::tryReserveStream(const Http2::Frame &pushPromiseFrame,
- const HPack::HttpHeader &requestHeader)
+static std::optional<QUrl> makeUrl(const HPack::HttpHeader &requestHeader)
{
- Q_ASSERT(pushPromiseFrame.type() == FrameType::PUSH_PROMISE);
-
QMap<QByteArray, QByteArray> pseudoHeaders;
for (const auto &field : requestHeader) {
if (field.name == ":scheme" || field.name == ":path"
|| field.name == ":authority" || field.name == ":method") {
if (field.value.isEmpty() || pseudoHeaders.contains(field.name))
- return false;
+ return {};
pseudoHeaders[field.name] = field.value;
}
}
if (pseudoHeaders.size() != 4) {
// All four required, HTTP/2 8.1.2.3.
- return false;
+ return {};
}
const QByteArray method = pseudoHeaders[":method"];
if (method.compare("get", Qt::CaseInsensitive) != 0 &&
- method.compare("head", Qt::CaseInsensitive) != 0)
- return false;
+ method.compare("head", Qt::CaseInsensitive) != 0)
+ return {};
QUrl url;
url.setScheme(QLatin1StringView(pseudoHeaders[":scheme"]));
@@ -1503,16 +1501,27 @@ bool QHttp2ProtocolHandler::tryReserveStream(const Http2::Frame &pushPromiseFram
url.setPath(QLatin1StringView(pseudoHeaders[":path"]));
if (!url.isValid())
+ return {};
+ return url;
+}
+
+bool QHttp2ProtocolHandler::tryReserveStream(const Http2::Frame &pushPromiseFrame,
+ const HPack::HttpHeader &requestHeader)
+{
+ Q_ASSERT(pushPromiseFrame.type() == FrameType::PUSH_PROMISE);
+
+ const auto url = makeUrl(requestHeader);
+ if (!url.has_value())
return false;
Q_ASSERT(activeStreams.contains(pushPromiseFrame.streamID()));
const Stream &associatedStream = activeStreams[pushPromiseFrame.streamID()];
const auto associatedUrl = urlkey_from_request(associatedStream.request());
- if (url.adjusted(QUrl::RemovePath) != associatedUrl.adjusted(QUrl::RemovePath))
+ if (url->adjusted(QUrl::RemovePath) != associatedUrl.adjusted(QUrl::RemovePath))
return false;
- const auto urlKey = url.toString();
+ const auto urlKey = url->toString();
if (promisedData.contains(urlKey)) // duplicate push promise
return false;