Commit ad5cd18e authored by Jeremy Roman's avatar Jeremy Roman Committed by Chromium LUCI CQ

Use base::MakeFixedFlatSet for never-sniffed mime types.

It's slightly more efficient.

Change-Id: I1bbc9e2ad89b82c81b67a3b3df615879a8d7519e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2562821
Auto-Submit: Jeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832645}
parent 1bdfd780
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "base/check_op.h" #include "base/check_op.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/containers/flat_set.h" #include "base/containers/fixed_flat_set.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
...@@ -248,12 +248,14 @@ void BlockResponseHeaders( ...@@ -248,12 +248,14 @@ void BlockResponseHeaders(
// disclosure of "application/zip" even though Chrome doesn't have built-in // disclosure of "application/zip" even though Chrome doesn't have built-in
// support for this resource type. And CORB also wants to protect // support for this resource type. And CORB also wants to protect
// "application/pdf" even though Chrome happens to support this resource type. // "application/pdf" even though Chrome happens to support this resource type.
base::flat_set<std::string>& GetNeverSniffedMimeTypes() { const auto& GetNeverSniffedMimeTypes() {
static base::NoDestructor<base::flat_set<std::string>> s_types{{ static constexpr auto kNeverSniffedMimeTypes = base::MakeFixedFlatSet<
base::StringPiece>({
// clang-format off
// The types below (zip, protobuf, etc.) are based on most commonly used // The types below (zip, protobuf, etc.) are based on most commonly used
// content types according to HTTP Archive - see: // content types according to HTTP Archive - see:
// https://github.com/whatwg/fetch/issues/860#issuecomment-457330454 // https://github.com/whatwg/fetch/issues/860#issuecomment-457330454
"application/gzip", "application/gzip",
"application/x-gzip", "application/x-gzip",
"application/x-protobuf", "application/x-protobuf",
"application/zip", "application/zip",
...@@ -308,15 +310,16 @@ base::flat_set<std::string>& GetNeverSniffedMimeTypes() { ...@@ -308,15 +310,16 @@ base::flat_set<std::string>& GetNeverSniffedMimeTypes() {
"multipart/byteranges", "multipart/byteranges",
// TODO(lukasza): https://crbug.com/802836#c11: Add // TODO(lukasza): https://crbug.com/802836#c11: Add
// application/signed-exchange. // application/signed-exchange.
}}; // clang-format on
});
// All items need to be lower-case, to support case-insensitive comparisons // All items need to be lower-case, to support case-insensitive comparisons
// later. // later.
DCHECK(std::all_of( DCHECK(std::all_of(kNeverSniffedMimeTypes.begin(),
s_types->begin(), s_types->end(), kNeverSniffedMimeTypes.end(),
[](const std::string& s) { return s == base::ToLowerASCII(s); })); [](const auto& s) { return s == base::ToLowerASCII(s); }));
return *s_types; return kNeverSniffedMimeTypes;
} }
} // namespace } // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment