diff --git a/netwerk/protocol/http/nsCORSListenerProxy.cpp b/netwerk/protocol/http/nsCORSListenerProxy.cpp index 3cd81931603a..e8fd724aa5c2 100644 --- a/netwerk/protocol/http/nsCORSListenerProxy.cpp +++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp @@ -210,25 +210,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; } }