From fdfe81fe5430065910173fbd9238c33cc0e7a2e1 Mon Sep 17 00:00:00 2001 From: Shadow Date: Fri, 14 Mar 2025 14:26:29 +0000 Subject: [PATCH] Issue #2703 - Part 3: Make cache entry request checking more readable. --- netwerk/protocol/http/nsCORSListenerProxy.cpp | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/netwerk/protocol/http/nsCORSListenerProxy.cpp b/netwerk/protocol/http/nsCORSListenerProxy.cpp index a1e6089523..7f0c06d04f 100644 --- a/netwerk/protocol/http/nsCORSListenerProxy.cpp +++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp @@ -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; } }