#include "third_party/blink/public/common/web_package/web_package_request_matcher.h"
#include <limits>
#include <memory>
#include <optional>
#include <string_view>
#include <utility>
#include "base/containers/contains.h"
#include "base/containers/span.h"
#include "base/numerics/checked_math.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "net/base/mime_util.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_util.h"
#include "net/http/structured_headers.h"
#include "third_party/blink/public/common/web_package/signed_exchange_consts.h"
namespace blink {
namespace {
constexpr char kIdentity[] = …;
class ContentNegotiationAlgorithm { … };
class ContentTypeNegotiation final : public ContentNegotiationAlgorithm { … };
class AcceptEncodingNegotiation final : public ContentNegotiationAlgorithm { … };
class AcceptLanguageNegotiation final : public ContentNegotiationAlgorithm { … };
std::unique_ptr<ContentNegotiationAlgorithm> GetContentNegotiationAlgorithm(
const std::string& field_name) { … }
std::optional<std::vector<std::pair<std::string, std::vector<std::string>>>>
ParseVariants(const std::string_view& str) { … }
std::optional<std::vector<std::vector<std::string>>> ParseVariantKey(
const std::string_view& str,
size_t num_variant_axes) { … }
std::optional<size_t> GetPossibleKeysIndex(
const std::vector<std::vector<std::string>>& sorted_variants,
const std::vector<std::string>& variant_key) { … }
}
WebPackageRequestMatcher::WebPackageRequestMatcher(
const net::HttpRequestHeaders& request_headers,
const std::string& accept_langs)
: … { … }
bool WebPackageRequestMatcher::MatchRequest(
const HeaderMap& response_headers) const { … }
std::vector<std::string>::const_iterator
WebPackageRequestMatcher::FindBestMatchingVariantKey(
const std::string& variants,
const std::vector<std::string>& variant_key_list) const { … }
std::optional<size_t> WebPackageRequestMatcher::FindBestMatchingIndex(
const std::string& variants) const { … }
std::vector<std::vector<std::string>> WebPackageRequestMatcher::CacheBehavior(
const std::vector<std::pair<std::string, std::vector<std::string>>>&
variants,
const net::HttpRequestHeaders& request_headers) { … }
bool WebPackageRequestMatcher::MatchRequest(
const net::HttpRequestHeaders& request_headers,
const HeaderMap& response_headers) { … }
std::vector<std::string>::const_iterator
WebPackageRequestMatcher::FindBestMatchingVariantKey(
const net::HttpRequestHeaders& request_headers,
const std::string& variants,
const std::vector<std::string>& variant_keys_list) { … }
std::optional<size_t> WebPackageRequestMatcher::FindBestMatchingIndex(
const net::HttpRequestHeaders& request_headers,
const std::string& variants) { … }
}