зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1443316 - part 3 - make cache entry request checking more readable; r=ckerschb
What we're really doing in CacheEntry::CheckRequest is checking: a) Whether the method is contained in our allowed methods; and b) Whether all of the headers are contained in our allowed headers. nsTArray lets us check directly for containing elements, so let's use that facility rather than rolling our own.
This commit is contained in:
Родитель
4e5f97268e
Коммит
72e140cbf6
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче