зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1890189: make cache control parsing case insensitive. r=necko-reviewers,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D216487
This commit is contained in:
Родитель
24ed804729
Коммит
8347a15889
|
@ -24,6 +24,17 @@ CacheControlParser::CacheControlParser(nsACString const& aHeader)
|
||||||
mPublic(false),
|
mPublic(false),
|
||||||
mPrivate(false),
|
mPrivate(false),
|
||||||
mImmutable(false) {
|
mImmutable(false) {
|
||||||
|
mDirectiveTokens[NO_CACHE] = AddCustomToken("no-cache", CASE_INSENSITIVE);
|
||||||
|
mDirectiveTokens[NO_STORE] = AddCustomToken("no-store", CASE_INSENSITIVE);
|
||||||
|
mDirectiveTokens[MAX_AGE] = AddCustomToken("max-age", CASE_INSENSITIVE);
|
||||||
|
mDirectiveTokens[MAX_STALE] = AddCustomToken("max-stale", CASE_INSENSITIVE);
|
||||||
|
mDirectiveTokens[MIN_FRESH] = AddCustomToken("min-fresh", CASE_INSENSITIVE);
|
||||||
|
mDirectiveTokens[STALE_WHILE_REVALIDATE] =
|
||||||
|
AddCustomToken("stale-while-revalidate", CASE_INSENSITIVE);
|
||||||
|
mDirectiveTokens[PUBLIC] = AddCustomToken("public", CASE_INSENSITIVE);
|
||||||
|
mDirectiveTokens[PRIVATE] = AddCustomToken("private", CASE_INSENSITIVE);
|
||||||
|
mDirectiveTokens[IMMUTABLE] = AddCustomToken("immutable", CASE_INSENSITIVE);
|
||||||
|
|
||||||
SkipWhites();
|
SkipWhites();
|
||||||
if (!CheckEOF()) {
|
if (!CheckEOF()) {
|
||||||
Directive();
|
Directive();
|
||||||
|
@ -33,24 +44,24 @@ CacheControlParser::CacheControlParser(nsACString const& aHeader)
|
||||||
void CacheControlParser::Directive() {
|
void CacheControlParser::Directive() {
|
||||||
do {
|
do {
|
||||||
SkipWhites();
|
SkipWhites();
|
||||||
if (CheckWord("no-cache")) {
|
if (Check(mDirectiveTokens[NO_CACHE])) {
|
||||||
mNoCache = true;
|
mNoCache = true;
|
||||||
IgnoreDirective(); // ignore any optionally added values
|
IgnoreDirective(); // ignore any optionally added values
|
||||||
} else if (CheckWord("no-store")) {
|
} else if (Check(mDirectiveTokens[NO_STORE])) {
|
||||||
mNoStore = true;
|
mNoStore = true;
|
||||||
} else if (CheckWord("max-age")) {
|
} else if (Check(mDirectiveTokens[MAX_AGE])) {
|
||||||
mMaxAgeSet = SecondsValue(&mMaxAge);
|
mMaxAgeSet = SecondsValue(&mMaxAge);
|
||||||
} else if (CheckWord("max-stale")) {
|
} else if (Check(mDirectiveTokens[MAX_STALE])) {
|
||||||
mMaxStaleSet = SecondsValue(&mMaxStale, PR_UINT32_MAX);
|
mMaxStaleSet = SecondsValue(&mMaxStale, PR_UINT32_MAX);
|
||||||
} else if (CheckWord("min-fresh")) {
|
} else if (Check(mDirectiveTokens[MIN_FRESH])) {
|
||||||
mMinFreshSet = SecondsValue(&mMinFresh);
|
mMinFreshSet = SecondsValue(&mMinFresh);
|
||||||
} else if (CheckWord("stale-while-revalidate")) {
|
} else if (Check(mDirectiveTokens[STALE_WHILE_REVALIDATE])) {
|
||||||
mStaleWhileRevalidateSet = SecondsValue(&mStaleWhileRevalidate);
|
mStaleWhileRevalidateSet = SecondsValue(&mStaleWhileRevalidate);
|
||||||
} else if (CheckWord("public")) {
|
} else if (Check(mDirectiveTokens[PUBLIC])) {
|
||||||
mPublic = true;
|
mPublic = true;
|
||||||
} else if (CheckWord("private")) {
|
} else if (Check(mDirectiveTokens[PRIVATE])) {
|
||||||
mPrivate = true;
|
mPrivate = true;
|
||||||
} else if (CheckWord("immutable")) {
|
} else if (Check(mDirectiveTokens[IMMUTABLE])) {
|
||||||
mImmutable = true;
|
mImmutable = true;
|
||||||
} else {
|
} else {
|
||||||
IgnoreDirective();
|
IgnoreDirective();
|
||||||
|
|
|
@ -27,7 +27,22 @@ class CacheControlParser final : Tokenizer {
|
||||||
bool Immutable();
|
bool Immutable();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum CacheControlDirective : uint32_t {
|
||||||
|
NO_CACHE = 0,
|
||||||
|
NO_STORE,
|
||||||
|
MAX_AGE,
|
||||||
|
MAX_STALE,
|
||||||
|
MIN_FRESH,
|
||||||
|
STALE_WHILE_REVALIDATE,
|
||||||
|
PUBLIC,
|
||||||
|
PRIVATE,
|
||||||
|
IMMUTABLE,
|
||||||
|
DIRECTIVE_UNKNOWN
|
||||||
|
};
|
||||||
|
Token mDirectiveTokens[DIRECTIVE_UNKNOWN];
|
||||||
|
|
||||||
void Directive();
|
void Directive();
|
||||||
|
|
||||||
void IgnoreDirective();
|
void IgnoreDirective();
|
||||||
[[nodiscard]] bool SecondsValue(uint32_t* seconds, uint32_t defaultVal = 0);
|
[[nodiscard]] bool SecondsValue(uint32_t* seconds, uint32_t defaultVal = 0);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче