diff --git a/src/Microsoft.AspNetCore.ResponseCaching/Internal/LoggerExtensions.cs b/src/Microsoft.AspNetCore.ResponseCaching/Internal/LoggerExtensions.cs index b900731..64c67f6 100644 --- a/src/Microsoft.AspNetCore.ResponseCaching/Internal/LoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.ResponseCaching/Internal/LoggerExtensions.cs @@ -31,7 +31,7 @@ internal static class LoggerExtensions private static Action _logResponseWithUnsuccessfulStatusCodeNotCacheable; private static Action _logNotModifiedIfNoneMatchStar; private static Action _logNotModifiedIfNoneMatchMatched; - private static Action _logNotModifiedIfUnmodifiedSinceSatisfied; + private static Action _logNotModifiedIfModifiedSinceSatisfied; private static Action _logNotModifiedServed; private static Action _logCachedResponseServed; private static Action _logGatewayTimeoutServed; @@ -119,10 +119,10 @@ static LoggerExtensions() logLevel: LogLevel.Debug, eventId: 19, formatString: $"The ETag {{ETag}} in the '{HeaderNames.IfNoneMatch}' header matched the ETag of a cached entry."); - _logNotModifiedIfUnmodifiedSinceSatisfied = LoggerMessage.Define( + _logNotModifiedIfModifiedSinceSatisfied = LoggerMessage.Define( logLevel: LogLevel.Debug, eventId: 20, - formatString: $"The last modified date of {{LastModified}} is before the date {{IfUnmodifiedSince}} specified in the '{HeaderNames.IfUnmodifiedSince}' header."); + formatString: $"The last modified date of {{LastModified}} is before the date {{IfModifiedSince}} specified in the '{HeaderNames.IfModifiedSince}' header."); _logNotModifiedServed = LoggerMessage.Define( logLevel: LogLevel.Information, eventId: 21, @@ -252,9 +252,9 @@ internal static void LogNotModifiedIfNoneMatchMatched(this ILogger logger, Entit _logNotModifiedIfNoneMatchMatched(logger, etag, null); } - internal static void LogNotModifiedIfUnmodifiedSinceSatisfied(this ILogger logger, DateTimeOffset lastModified, DateTimeOffset ifUnmodifiedSince) + internal static void LogNotModifiedIfModifiedSinceSatisfied(this ILogger logger, DateTimeOffset lastModified, DateTimeOffset ifModifiedSince) { - _logNotModifiedIfUnmodifiedSinceSatisfied(logger, lastModified, ifUnmodifiedSince, null); + _logNotModifiedIfModifiedSinceSatisfied(logger, lastModified, ifModifiedSince, null); } internal static void LogNotModifiedServed(this ILogger logger) diff --git a/src/Microsoft.AspNetCore.ResponseCaching/ResponseCachingMiddleware.cs b/src/Microsoft.AspNetCore.ResponseCaching/ResponseCachingMiddleware.cs index 72dbb5d..fa7cadf 100644 --- a/src/Microsoft.AspNetCore.ResponseCaching/ResponseCachingMiddleware.cs +++ b/src/Microsoft.AspNetCore.ResponseCaching/ResponseCachingMiddleware.cs @@ -371,13 +371,13 @@ internal static bool ContentIsNotModified(ResponseCachingContext context) } else { - var ifUnmodifiedSince = context.TypedRequestHeaders.IfUnmodifiedSince; - if (ifUnmodifiedSince != null) + var ifModifiedSince = context.TypedRequestHeaders.IfModifiedSince; + if (ifModifiedSince != null) { var lastModified = cachedResponseHeaders.LastModified ?? cachedResponseHeaders.Date; - if (lastModified <= ifUnmodifiedSince) + if (lastModified <= ifModifiedSince) { - context.Logger.LogNotModifiedIfUnmodifiedSinceSatisfied(lastModified.Value, ifUnmodifiedSince.Value); + context.Logger.LogNotModifiedIfModifiedSinceSatisfied(lastModified.Value, ifModifiedSince.Value); return true; } } diff --git a/test/Microsoft.AspNetCore.ResponseCaching.Tests/ResponseCachingMiddlewareTests.cs b/test/Microsoft.AspNetCore.ResponseCaching.Tests/ResponseCachingMiddlewareTests.cs index fb74241..11abbd3 100644 --- a/test/Microsoft.AspNetCore.ResponseCaching.Tests/ResponseCachingMiddlewareTests.cs +++ b/test/Microsoft.AspNetCore.ResponseCaching.Tests/ResponseCachingMiddlewareTests.cs @@ -156,14 +156,14 @@ public void ContentIsNotModified_NotConditionalRequest_False() } [Fact] - public void ContentIsNotModified_IfUnmodifiedSince_FallsbackToDateHeader() + public void ContentIsNotModified_IfModifiedSince_FallsbackToDateHeader() { var utcNow = DateTimeOffset.UtcNow; var sink = new TestSink(); var context = TestUtils.CreateTestContext(sink); context.CachedResponseHeaders = new ResponseHeaders(new HeaderDictionary()); - context.TypedRequestHeaders.IfUnmodifiedSince = utcNow; + context.TypedRequestHeaders.IfModifiedSince = utcNow; // Verify modifications in the past succeeds context.CachedResponseHeaders.Date = utcNow - TimeSpan.FromSeconds(10); @@ -182,19 +182,19 @@ public void ContentIsNotModified_IfUnmodifiedSince_FallsbackToDateHeader() // Verify logging TestUtils.AssertLoggedMessages( sink.Writes, - LoggedMessage.NotModifiedIfUnmodifiedSinceSatisfied, - LoggedMessage.NotModifiedIfUnmodifiedSinceSatisfied); + LoggedMessage.NotModifiedIfModifiedSinceSatisfied, + LoggedMessage.NotModifiedIfModifiedSinceSatisfied); } [Fact] - public void ContentIsNotModified_IfUnmodifiedSince_LastModifiedOverridesDateHeader() + public void ContentIsNotModified_IfModifiedSince_LastModifiedOverridesDateHeader() { var utcNow = DateTimeOffset.UtcNow; var sink = new TestSink(); var context = TestUtils.CreateTestContext(sink); context.CachedResponseHeaders = new ResponseHeaders(new HeaderDictionary()); - context.TypedRequestHeaders.IfUnmodifiedSince = utcNow; + context.TypedRequestHeaders.IfModifiedSince = utcNow; // Verify modifications in the past succeeds context.CachedResponseHeaders.Date = utcNow + TimeSpan.FromSeconds(10); @@ -216,20 +216,20 @@ public void ContentIsNotModified_IfUnmodifiedSince_LastModifiedOverridesDateHead // Verify logging TestUtils.AssertLoggedMessages( sink.Writes, - LoggedMessage.NotModifiedIfUnmodifiedSinceSatisfied, - LoggedMessage.NotModifiedIfUnmodifiedSinceSatisfied); + LoggedMessage.NotModifiedIfModifiedSinceSatisfied, + LoggedMessage.NotModifiedIfModifiedSinceSatisfied); } [Fact] - public void ContentIsNotModified_IfNoneMatch_Overrides_IfUnmodifiedSince_ToTrue() + public void ContentIsNotModified_IfNoneMatch_Overrides_IfModifiedSince_ToTrue() { var utcNow = DateTimeOffset.UtcNow; var sink = new TestSink(); var context = TestUtils.CreateTestContext(sink); context.CachedResponseHeaders = new ResponseHeaders(new HeaderDictionary()); - // This would fail the IfUnmodifiedSince checks - context.TypedRequestHeaders.IfUnmodifiedSince = utcNow; + // This would fail the IfModifiedSince checks + context.TypedRequestHeaders.IfModifiedSince = utcNow; context.CachedResponseHeaders.LastModified = utcNow + TimeSpan.FromSeconds(10); context.TypedRequestHeaders.IfNoneMatch = new List(new[] { EntityTagHeaderValue.Any }); @@ -240,15 +240,15 @@ public void ContentIsNotModified_IfNoneMatch_Overrides_IfUnmodifiedSince_ToTrue( } [Fact] - public void ContentIsNotModified_IfNoneMatch_Overrides_IfUnmodifiedSince_ToFalse() + public void ContentIsNotModified_IfNoneMatch_Overrides_IfModifiedSince_ToFalse() { var utcNow = DateTimeOffset.UtcNow; var sink = new TestSink(); var context = TestUtils.CreateTestContext(sink); context.CachedResponseHeaders = new ResponseHeaders(new HeaderDictionary()); - // This would pass the IfUnmodifiedSince checks - context.TypedRequestHeaders.IfUnmodifiedSince = utcNow; + // This would pass the IfModifiedSince checks + context.TypedRequestHeaders.IfModifiedSince = utcNow; context.CachedResponseHeaders.LastModified = utcNow - TimeSpan.FromSeconds(10); context.TypedRequestHeaders.IfNoneMatch = new List(new[] { new EntityTagHeaderValue("\"E1\"") }); diff --git a/test/Microsoft.AspNetCore.ResponseCaching.Tests/ResponseCachingTests.cs b/test/Microsoft.AspNetCore.ResponseCaching.Tests/ResponseCachingTests.cs index c867115..8a6d2f1 100644 --- a/test/Microsoft.AspNetCore.ResponseCaching.Tests/ResponseCachingTests.cs +++ b/test/Microsoft.AspNetCore.ResponseCaching.Tests/ResponseCachingTests.cs @@ -453,7 +453,7 @@ public async void Serves304_IfIfModifiedSince_Satisfied() { var client = server.CreateClient(); var initialResponse = await client.GetAsync(""); - client.DefaultRequestHeaders.IfUnmodifiedSince = DateTimeOffset.MaxValue; + client.DefaultRequestHeaders.IfModifiedSince = DateTimeOffset.MaxValue; var subsequentResponse = await client.GetAsync(""); initialResponse.EnsureSuccessStatusCode(); @@ -473,7 +473,7 @@ public async void ServesCachedContent_IfIfModifiedSince_NotSatisfied() { var client = server.CreateClient(); var initialResponse = await client.GetAsync(""); - client.DefaultRequestHeaders.IfUnmodifiedSince = DateTimeOffset.MinValue; + client.DefaultRequestHeaders.IfModifiedSince = DateTimeOffset.MinValue; var subsequentResponse = await client.GetAsync(""); await AssertCachedResponseAsync(initialResponse, subsequentResponse); diff --git a/test/Microsoft.AspNetCore.ResponseCaching.Tests/TestUtils.cs b/test/Microsoft.AspNetCore.ResponseCaching.Tests/TestUtils.cs index 76f6597..b4b7373 100644 --- a/test/Microsoft.AspNetCore.ResponseCaching.Tests/TestUtils.cs +++ b/test/Microsoft.AspNetCore.ResponseCaching.Tests/TestUtils.cs @@ -184,7 +184,7 @@ internal class LoggedMessage internal static LoggedMessage ResponseWithUnsuccessfulStatusCodeNotCacheable => new LoggedMessage(17, LogLevel.Debug); internal static LoggedMessage NotModifiedIfNoneMatchStar => new LoggedMessage(18, LogLevel.Debug); internal static LoggedMessage NotModifiedIfNoneMatchMatched => new LoggedMessage(19, LogLevel.Debug); - internal static LoggedMessage NotModifiedIfUnmodifiedSinceSatisfied => new LoggedMessage(20, LogLevel.Debug); + internal static LoggedMessage NotModifiedIfModifiedSinceSatisfied => new LoggedMessage(20, LogLevel.Debug); internal static LoggedMessage NotModifiedServed => new LoggedMessage(21, LogLevel.Information); internal static LoggedMessage CachedResponseServed => new LoggedMessage(22, LogLevel.Information); internal static LoggedMessage GatewayTimeoutServed => new LoggedMessage(23, LogLevel.Information);