From 8ce261f6d857e8b05c8043042fce101cb95cd868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Mon, 8 Jan 2024 10:04:43 +0100 Subject: Http2: move assemble_hpack_block declaration to header Pick-to: 6.7 Change-Id: I5033d433d2aa499007a6e436dbb70d9c48315e8b Reviewed-by: Alexey Edelev --- src/network/access/http2/http2protocol.cpp | 27 +++++++++++++++++++++++++++ src/network/access/http2/http2protocol_p.h | 3 +++ src/network/access/qhttp2protocolhandler.cpp | 28 +--------------------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/network/access/http2/http2protocol.cpp b/src/network/access/http2/http2protocol.cpp index 2b754830fb..1e7291e48e 100644 --- a/src/network/access/http2/http2protocol.cpp +++ b/src/network/access/http2/http2protocol.cpp @@ -197,6 +197,33 @@ bool is_protocol_upgraded(const QHttpNetworkReply &reply) return false; } +std::vector assemble_hpack_block(const std::vector &frames) +{ + std::vector hpackBlock; + + quint32 total = 0; + for (const auto &frame : frames) { + if (qAddOverflow(total, frame.hpackBlockSize(), &total)) + return hpackBlock; + } + + if (!total) + return hpackBlock; + + hpackBlock.resize(total); + auto dst = hpackBlock.begin(); + for (const auto &frame : frames) { + if (const auto hpackBlockSize = frame.hpackBlockSize()) { + const uchar *src = frame.hpackBlockBegin(); + std::copy(src, src + hpackBlockSize, dst); + dst += hpackBlockSize; + } + } + + return hpackBlock; +} + + } // namespace Http2 QT_END_NAMESPACE diff --git a/src/network/access/http2/http2protocol_p.h b/src/network/access/http2/http2protocol_p.h index e5068ad81a..fb5ff199c5 100644 --- a/src/network/access/http2/http2protocol_p.h +++ b/src/network/access/http2/http2protocol_p.h @@ -21,6 +21,8 @@ #include #include +#include + // Different HTTP/2 constants/values as defined by RFC 7540. QT_BEGIN_NAMESPACE @@ -118,6 +120,7 @@ const qint32 qtDefaultStreamReceiveWindowSize = maxSessionReceiveWindowSize / 10 struct Frame configurationToSettingsFrame(const QHttp2Configuration &configuration); QByteArray settingsFrameToBase64(const Frame &settingsFrame); void appendProtocolUpgradeHeaders(const QHttp2Configuration &configuration, QHttpNetworkRequest *request); +std::vector assemble_hpack_block(const std::vector &frames); extern const Q_AUTOTEST_EXPORT char Http2clientPreface[clientPrefaceLength]; diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp index d159a1f885..4e7c1e1d61 100644 --- a/src/network/access/qhttp2protocolhandler.cpp +++ b/src/network/access/qhttp2protocolhandler.cpp @@ -88,32 +88,6 @@ HPack::HttpHeader build_headers(const QHttpNetworkRequest &request, quint32 maxH return header; } -std::vector assemble_hpack_block(const std::vector &frames) -{ - std::vector hpackBlock; - - quint32 total = 0; - for (const auto &frame : frames) { - if (qAddOverflow(total, frame.hpackBlockSize(), &total)) - return hpackBlock; - } - - if (!total) - return hpackBlock; - - hpackBlock.resize(total); - auto dst = hpackBlock.begin(); - for (const auto &frame : frames) { - if (const auto hpackBlockSize = frame.hpackBlockSize()) { - const uchar *src = frame.hpackBlockBegin(); - std::copy(src, src + hpackBlockSize, dst); - dst += hpackBlockSize; - } - } - - return hpackBlock; -} - QUrl urlkey_from_request(const QHttpNetworkRequest &request) { QUrl url; @@ -962,7 +936,7 @@ void QHttp2ProtocolHandler::handleContinuedHEADERS() // has yet to see the reset. } - std::vector hpackBlock(assemble_hpack_block(continuedFrames)); + std::vector hpackBlock(Http2::assemble_hpack_block(continuedFrames)); const bool hasHeaderFields = !hpackBlock.empty(); if (hasHeaderFields) { HPack::BitIStream inputStream{&hpackBlock[0], &hpackBlock[0] + hpackBlock.size()}; -- cgit v1.2.3