diff options
Diffstat (limited to 'src/network/access/http2/hpack.cpp')
-rw-r--r-- | src/network/access/http2/hpack.cpp | 89 |
1 files changed, 48 insertions, 41 deletions
diff --git a/src/network/access/http2/hpack.cpp b/src/network/access/http2/hpack.cpp index 7461095f0a..9e970dda53 100644 --- a/src/network/access/http2/hpack.cpp +++ b/src/network/access/http2/hpack.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "bitstreams_p.h" #include "hpack_p.h" @@ -127,7 +91,7 @@ bool read_bit_pattern(const BitPattern &pattern, BitIStream &inputStream) return true; } -bool is_request_pseudo_header(const QByteArray &name) +bool is_request_pseudo_header(QByteArrayView name) { return name == ":method" || name == ":scheme" || name == ":authority" || name == ":path"; @@ -230,8 +194,8 @@ bool Encoder::encodeRequestPseudoHeaders(BitOStream &outputStream, using size_type = decltype(header.size()); bool methodFound = false; - const char *headerName[] = {":authority", ":scheme", ":path"}; - const size_type nHeaders = sizeof headerName / sizeof headerName[0]; + constexpr QByteArrayView headerName[] = {":authority", ":scheme", ":path"}; + constexpr size_type nHeaders = std::size(headerName); bool headerFound[nHeaders] = {}; for (const auto &field : header) { @@ -540,6 +504,49 @@ void Decoder::handleStreamError(BitIStream &inputStream) // HTTP2 layer will end with session error/COMPRESSION_ERROR. } +std::optional<QUrl> makePromiseKeyUrl(const HttpHeader &requestHeader) +{ + constexpr QByteArrayView names[] = { ":authority", ":method", ":path", ":scheme" }; + enum PseudoHeaderEnum + { + Authority, + Method, + Path, + Scheme + }; + std::array<std::optional<QByteArrayView>, std::size(names)> pseudoHeaders{}; + for (const auto &field : requestHeader) { + const auto *it = std::find(std::begin(names), std::end(names), QByteArrayView(field.name)); + if (it != std::end(names)) { + const auto index = std::distance(std::begin(names), it); + if (field.value.isEmpty() || pseudoHeaders.at(index).has_value()) + return {}; + pseudoHeaders[index] = field.value; + } + } + + auto optionalIsSet = [](const auto &x) { return x.has_value(); }; + if (!std::all_of(pseudoHeaders.begin(), pseudoHeaders.end(), optionalIsSet)) { + // All four required, HTTP/2 8.1.2.3. + return {}; + } + + const QByteArrayView method = pseudoHeaders[Method].value(); + if (method.compare("get", Qt::CaseInsensitive) != 0 && + method.compare("head", Qt::CaseInsensitive) != 0) { + return {}; + } + + QUrl url; + url.setScheme(QLatin1StringView(pseudoHeaders[Scheme].value())); + url.setAuthority(QLatin1StringView(pseudoHeaders[Authority].value())); + url.setPath(QLatin1StringView(pseudoHeaders[Path].value())); + + if (!url.isValid()) + return {}; + return url; +} + } QT_END_NAMESPACE |