Skip to content

Commit

Permalink
Refactor header key management
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
bluemodus-brandon committed Jul 11, 2024
1 parent 2a9434d commit dd1f4a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/XperienceCommunity.OutputCache/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit dd1f4a0

Please sign in to comment.