Only look-up Cache-Control once (#23329)

Only look-up the Cache-Control header once, rather than twice if non-empty.
This commit is contained in:
Martin Costello 2020-06-24 23:48:36 +01:00 committed by GitHub
parent cd9da1c350
commit c19f3d29ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -34,11 +34,12 @@ namespace Microsoft.AspNetCore.ResponseCaching
public virtual bool AllowCacheLookup(ResponseCachingContext context)
{
var requestHeaders = context.HttpContext.Request.Headers;
var cacheControl = requestHeaders[HeaderNames.CacheControl];
// Verify request cache-control parameters
if (!StringValues.IsNullOrEmpty(requestHeaders[HeaderNames.CacheControl]))
if (!StringValues.IsNullOrEmpty(cacheControl))
{
if (HeaderUtilities.ContainsCacheDirective(requestHeaders[HeaderNames.CacheControl], CacheControlHeaderValue.NoCacheString))
if (HeaderUtilities.ContainsCacheDirective(cacheControl, CacheControlHeaderValue.NoCacheString))
{
context.Logger.RequestWithNoCacheNotCacheable();
return false;