diff options
Diffstat (limited to 'src/network/access/http2/http2protocol.cpp')
-rw-r--r-- | src/network/access/http2/http2protocol.cpp | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/src/network/access/http2/http2protocol.cpp b/src/network/access/http2/http2protocol.cpp index 966f294e81..8e7e176c41 100644 --- a/src/network/access/http2/http2protocol.cpp +++ b/src/network/access/http2/http2protocol.cpp @@ -76,12 +76,10 @@ void appendProtocolUpgradeHeaders(const QHttp2Configuration &config, QHttpNetwor Q_ASSERT(request); // RFC 2616, 14.10 // RFC 7540, 3.2 - QByteArray value(request->headerField("Connection")); + const QByteArray connectionHeader = request->headerField("Connection"); + const auto separator = connectionHeader.isEmpty() ? QByteArrayView() : QByteArrayView(", "); // We _append_ 'Upgrade': - if (value.size()) - value += ", "; - - value += "Upgrade, HTTP2-Settings"; + QByteArray value = connectionHeader + separator + "Upgrade, HTTP2-Settings"; request->setHeaderField("Connection", value); // This we just (re)write. request->setHeaderField("Upgrade", "h2c"); @@ -186,19 +184,45 @@ QNetworkReply::NetworkError qt_error(quint32 errorCode) bool is_protocol_upgraded(const QHttpNetworkReply &reply) { - if (reply.statusCode() == 101) { - // Do some minimal checks here - we expect 'Upgrade: h2c' to be found. - const auto &header = reply.header(); - for (const QPair<QByteArray, QByteArray> &field : header) { - if (field.first.compare("upgrade", Qt::CaseInsensitive) == 0 && - field.second.compare("h2c", Qt::CaseInsensitive) == 0) - return true; - } + if (reply.statusCode() != 101) + return false; + + // Do some minimal checks here - we expect 'Upgrade: h2c' to be found. + for (const auto &v : reply.header().values(QHttpHeaders::WellKnownHeader::Upgrade)) { + if (v.compare("h2c", Qt::CaseInsensitive) == 0) + return true; } return false; } +std::vector<uchar> assemble_hpack_block(const std::vector<Frame> &frames) +{ + std::vector<uchar> hpackBlock; + + size_t total = 0; + for (const auto &frame : frames) { + if (qAddOverflow(total, size_t{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 |