Issue #2703 - Part 3: Make cache entry request checking more readable.

This commit is contained in:
Shadow 2025-03-14 14:26:29 +00:00 committed by roytam1
commit fdfe81fe54

View file

@ -238,25 +238,26 @@ nsPreflightCache::CacheEntry::CheckRequest(const nsCString& aMethod,
PurgeExpired(TimeStamp::NowLoRes());
if (!aMethod.EqualsLiteral("GET") && !aMethod.EqualsLiteral("POST")) {
uint32_t i;
for (i = 0; i < mMethods.Length(); ++i) {
if (aMethod.Equals(mMethods[i].token))
break;
}
if (i == mMethods.Length()) {
struct CheckToken {
bool Equals(const TokenTime& e, const nsCString& method) const {
return e.token.Equals(method);
}
};
if (!mMethods.Contains(aMethod, CheckToken())) {
return false;
}
}
for (uint32_t i = 0; i < aHeaders.Length(); ++i) {
uint32_t j;
const auto& comparator = nsCaseInsensitiveCStringComparator();
for (j = 0; j < mHeaders.Length(); ++j) {
if (aHeaders[i].Equals(mHeaders[j].token, comparator)) {
break;
}
const struct CheckHeaderToken {
bool Equals(const TokenTime& e, const nsCString& header) const {
return e.token.Equals(header, comparator);
}
if (j == mHeaders.Length()) {
const nsCaseInsensitiveCStringComparator comparator;
} checker;
for (uint32_t i = 0; i < aHeaders.Length(); ++i) {
if (!mHeaders.Contains(aHeaders[i], checker)) {
return false;
}
}