forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcors_exempt_headers.cc
56 lines (42 loc) · 1.66 KB
/
cors_exempt_headers.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromecast/cast_core/cors_exempt_headers.h"
#include "base/lazy_instance.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "chromecast/common/cors_exempt_headers.h"
namespace chromecast {
namespace {
constexpr char kAcceptLanguageHeader[] = "Accept-Language";
// Provides a list of CORS exempt headers for Cast Core.
class CorsExemptHeaders {
public:
CorsExemptHeaders() : cors_exempt_headers_({kAcceptLanguageHeader}) {
base::ranges::copy(GetLegacyCorsExemptHeaders(),
std::back_inserter(cors_exempt_headers_));
}
// Returns the list of CORS exempt headers.
const std::vector<std::string>& cors_exempt_headers() const {
return cors_exempt_headers_;
}
// Checks if the header is CORS exempt using case-insensitive comparison.
bool IsExempt(base::StringPiece header) const {
return base::ranges::any_of(
cors_exempt_headers_, [header](const std::string& cors_exempt_header) {
return base::EqualsCaseInsensitiveASCII(cors_exempt_header, header);
});
}
private:
std::vector<std::string> cors_exempt_headers_;
};
base::LazyInstance<CorsExemptHeaders>::Leaky g_cors_exempt_headers =
LAZY_INSTANCE_INITIALIZER;
} // namespace
const std::vector<std::string>& GetCastCoreCorsExemptHeadersList() {
return g_cors_exempt_headers.Get().cors_exempt_headers();
}
bool IsHeaderCorsExempt(base::StringPiece header) {
return g_cors_exempt_headers.Get().IsExempt(header);
}
} // namespace chromecast