From dd1f4a043808d6d3c9cd079b519b0732894fab43 Mon Sep 17 00:00:00 2001 From: Brandon Henricks <78803523+bluemodus-brandon@users.noreply.github.com> Date: Thu, 11 Jul 2024 08:57:32 -0400 Subject: [PATCH] Refactor header key management - Introduced a new `HeaderKeys` struct in `Constants.cs` to centralize the management of header keys, including a constant for `RequestVerificationToken`. - Updated `XperienceOutputCachePolicy.cs` to utilize the `RequestVerificationToken` from `HeaderKeys` struct, replacing the hardcoded string. This change improves code maintainability and consistency. --- src/XperienceCommunity.OutputCache/Constants.cs | 5 +++++ .../Policies/XperienceOutputCachePolicy.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/XperienceCommunity.OutputCache/Constants.cs b/src/XperienceCommunity.OutputCache/Constants.cs index e125ec7..ee6c304 100644 --- a/src/XperienceCommunity.OutputCache/Constants.cs +++ b/src/XperienceCommunity.OutputCache/Constants.cs @@ -13,6 +13,11 @@ internal readonly struct ItemKeys internal const string DependencyKeys = "DependencyKeys"; } + internal readonly struct HeaderKeys + { + internal const string RequestVerificationToken = "RequestVerificationToken"; + } + internal readonly struct CacheSegments { /// diff --git a/src/XperienceCommunity.OutputCache/Policies/XperienceOutputCachePolicy.cs b/src/XperienceCommunity.OutputCache/Policies/XperienceOutputCachePolicy.cs index d3c78ea..7bcfb5f 100644 --- a/src/XperienceCommunity.OutputCache/Policies/XperienceOutputCachePolicy.cs +++ b/src/XperienceCommunity.OutputCache/Policies/XperienceOutputCachePolicy.cs @@ -122,7 +122,7 @@ private static bool AttemptOutputCaching(OutputCacheContext context) } // Verify existence of anti-forgery token - if (!StringValues.IsNullOrEmpty(request.Headers["RequestVerificationToken"])) + if (!StringValues.IsNullOrEmpty(request.Headers[Constants.HeaderKeys.RequestVerificationToken])) { return false; }