Introduce type option in use-as-dictionary response header
A new `type` option is introduced by https://github.com/WICG/compression-dictionary-transport/pull/46/ . Currently we only supports `raw` type. Bug: 1413922 Change-Id: I76bb8fc5de851dee838d402a998f991f3ec7a051 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4763627 Commit-Queue: Tsuyoshi Horo <horo@chromium.org> Reviewed-by: Patrick Meenan <pmeenan@chromium.org> Cr-Commit-Position: refs/heads/main@{#1181759}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
1eeb4d66a0
commit
169031f4af
services/network/shared_dictionary
@ -25,6 +25,7 @@ const char kUseAsDictionaryHeaderName[] = "use-as-dictionary";
|
||||
const char kOptionNameMatch[] = "match";
|
||||
const char kOptionNameExpires[] = "expires";
|
||||
const char kOptionNameAlgorithms[] = "algorithms";
|
||||
const char kOptionNameType[] = "type";
|
||||
|
||||
size_t GetDictionarySizeLimit() {
|
||||
return g_dictionary_size_limit;
|
||||
|
@ -55,6 +55,9 @@ COMPONENT_EXPORT(NETWORK_SERVICE) extern const char kOptionNameExpires[];
|
||||
// The dictionary option name of "algorithms".
|
||||
COMPONENT_EXPORT(NETWORK_SERVICE) extern const char kOptionNameAlgorithms[];
|
||||
|
||||
// The dictionary option name of "type".
|
||||
COMPONENT_EXPORT(NETWORK_SERVICE) extern const char kOptionNameType[];
|
||||
|
||||
} // namespace network::shared_dictionary
|
||||
|
||||
#endif // SERVICES_NETWORK_SHARED_DICTIONARY_SHARED_DICTIONARY_CONSTANTS_H_
|
||||
|
@ -547,6 +547,16 @@ TEST_P(SharedDictionaryManagerTest, WriterForUseAsDictionaryHeader) {
|
||||
|
||||
// Unsupported `algorithms` value. We only support sha-256.
|
||||
{"match=\"test\", algorithms=(sha-512)", false},
|
||||
|
||||
// We support `raw` type.
|
||||
{"match=\"test\", type=raw", true},
|
||||
{"match=\"test\", type=(raw)", true},
|
||||
// The type must be a token.
|
||||
{"match=\"test\", type=\"raw\"", false},
|
||||
// We only support `raw` type.
|
||||
{"match=\"test\", type=other", false},
|
||||
// We don't support multiple types.
|
||||
{"match=\"test\", type=(raw,rawx)", false},
|
||||
};
|
||||
for (const auto& testcase : kTestCases) {
|
||||
SCOPED_TRACE(base::StringPrintf("header_string: %s",
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "services/network/shared_dictionary/shared_dictionary_storage.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
|
||||
#include "base/feature_list.h"
|
||||
#include "base/strings/pattern.h"
|
||||
@ -24,19 +25,24 @@ namespace network {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr std::string_view kDefaultTypeRaw = "raw";
|
||||
|
||||
class UseAsDictionaryHeaderInfo {
|
||||
public:
|
||||
UseAsDictionaryHeaderInfo(std::string match,
|
||||
absl::optional<base::TimeDelta> expiration,
|
||||
absl::optional<std::vector<std::string>> algorithms)
|
||||
absl::optional<std::vector<std::string>> algorithms,
|
||||
std::string type)
|
||||
: match(std::move(match)),
|
||||
expiration(expiration),
|
||||
algorithms(std::move(algorithms)) {}
|
||||
algorithms(std::move(algorithms)),
|
||||
type(std::move(type)) {}
|
||||
~UseAsDictionaryHeaderInfo() = default;
|
||||
|
||||
std::string match;
|
||||
absl::optional<base::TimeDelta> expiration;
|
||||
absl::optional<std::vector<std::string>> algorithms;
|
||||
std::string type;
|
||||
};
|
||||
|
||||
absl::optional<UseAsDictionaryHeaderInfo> ParseUseAsDictionaryHeaderInfo(
|
||||
@ -56,6 +62,7 @@ absl::optional<UseAsDictionaryHeaderInfo> ParseUseAsDictionaryHeaderInfo(
|
||||
absl::optional<std::string> match_value;
|
||||
absl::optional<base::TimeDelta> expires_value;
|
||||
absl::optional<std::vector<std::string>> algorithms_value;
|
||||
std::string type_value = std::string(kDefaultTypeRaw);
|
||||
for (const auto& entry : dictionary.value()) {
|
||||
if (entry.first == shared_dictionary::kOptionNameMatch) {
|
||||
if ((entry.second.member.size() != 1u) ||
|
||||
@ -79,13 +86,19 @@ absl::optional<UseAsDictionaryHeaderInfo> ParseUseAsDictionaryHeaderInfo(
|
||||
tmp_vec.push_back(algorithms_item.item.GetString());
|
||||
}
|
||||
algorithms_value = std::move(tmp_vec);
|
||||
} else if (entry.first == shared_dictionary::kOptionNameType) {
|
||||
if ((entry.second.member.size() != 1u) ||
|
||||
!entry.second.member.front().item.is_token()) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
type_value = entry.second.member.front().item.GetString();
|
||||
}
|
||||
}
|
||||
if (!match_value) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
return UseAsDictionaryHeaderInfo(*match_value, std::move(expires_value),
|
||||
std::move(algorithms_value));
|
||||
std::move(algorithms_value), type_value);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -127,6 +140,10 @@ SharedDictionaryStorage::MaybeCreateWriter(
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if (info->type != kDefaultTypeRaw) {
|
||||
// Currently we only support `raw` type.
|
||||
return nullptr;
|
||||
}
|
||||
// Do not write an existing shared dictionary from the HTTP caches to the
|
||||
// shared dictionary storage. Note that IsAlreadyRegistered() can return false
|
||||
// even when `was_fetched_via_cache` is true. This is because the shared
|
||||
|
Reference in New Issue
Block a user