diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileResultExecutorBase.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileResultExecutorBase.cs index c632b2f150..bd66edfe3a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileResultExecutorBase.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileResultExecutorBase.cs @@ -195,6 +195,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure if (etag != null) { ifMatchState = GetEtagMatchState( + useStrongComparison: true, etagHeader: ifMatch, etag: etag, matchFoundState: PreconditionState.ShouldProcess, @@ -211,6 +212,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure if (etag != null) { ifNoneMatchState = GetEtagMatchState( + useStrongComparison: false, etagHeader: ifNoneMatch, etag: etag, matchFoundState: PreconditionState.NotModified, @@ -245,6 +247,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure } private static PreconditionState GetEtagMatchState( + bool useStrongComparison, IList etagHeader, EntityTagHeaderValue etag, PreconditionState matchFoundState, @@ -255,7 +258,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure var state = matchNotFoundState; foreach (var entityTag in etagHeader) { - if (entityTag.Equals(EntityTagHeaderValue.Any) || entityTag.Compare(etag, useStrongComparison: true)) + if (entityTag.Equals(EntityTagHeaderValue.Any) || entityTag.Compare(etag, useStrongComparison)) { state = matchFoundState; break; diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileResultTest.cs index c169414a63..807f135930 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileResultTest.cs @@ -252,10 +252,12 @@ namespace Microsoft.AspNetCore.Mvc } [Theory] - [InlineData("\"Etag\"", "\"NotEtag\"", "\"Etag\"")] - [InlineData("\"Etag\"", null, null)] - [InlineData(null, "\"NotEtag\"", "\"Etag\"")] - public void GetPreconditionState_ShouldProcess(string ifMatch, string ifNoneMatch, string ifRange) + [InlineData("\"Etag\"", "\"NotEtag\"", true, "\"Etag\"")] + [InlineData("\"Etag\"", "\"NotEtag\"", false, "\"Etag\"")] + [InlineData("\"Etag\"", null, false, null)] + [InlineData(null, "\"NotEtag\"", true, "\"Etag\"")] + [InlineData(null, "\"NotEtag\"", false, "\"Etag\"")] + public void GetPreconditionState_ShouldProcess(string ifMatch, string ifNoneMatch, bool isWeak, string ifRange) { // Arrange var actionContext = new ActionContext(); @@ -272,7 +274,7 @@ namespace Microsoft.AspNetCore.Mvc httpRequestHeaders.IfNoneMatch = ifNoneMatch == null ? null : new[] { - new EntityTagHeaderValue(ifNoneMatch), + new EntityTagHeaderValue(ifNoneMatch, isWeak), }; httpRequestHeaders.IfRange = ifRange == null ? null : new RangeConditionHeaderValue(ifRange); httpRequestHeaders.IfUnmodifiedSince = lastModified; @@ -291,10 +293,12 @@ namespace Microsoft.AspNetCore.Mvc } [Theory] - [InlineData("\"NotEtag\"", null)] - [InlineData("\"Etag\"", "\"Etag\"")] - [InlineData(null, null)] - public void GetPreconditionState_ShouldNotProcess_PreconditionFailed(string ifMatch, string ifNoneMatch) + [InlineData("\"NotEtag\"", null, true)] + [InlineData("\"NotEtag\"", null, false)] + [InlineData("\"Etag\"", "\"Etag\"", true)] + [InlineData("\"Etag\"", "\"Etag\"", false)] + [InlineData(null, null, false)] + public void GetPreconditionState_ShouldNotProcess_PreconditionFailed(string ifMatch, string ifNoneMatch, bool isWeak) { // Arrange var actionContext = new ActionContext(); @@ -310,7 +314,7 @@ namespace Microsoft.AspNetCore.Mvc httpRequestHeaders.IfNoneMatch = ifNoneMatch == null ? null : new[] { - new EntityTagHeaderValue(ifNoneMatch), + new EntityTagHeaderValue(ifNoneMatch, isWeak), }; httpRequestHeaders.IfUnmodifiedSince = DateTimeOffset.MinValue; httpRequestHeaders.IfModifiedSince = DateTimeOffset.MinValue.AddDays(2); @@ -328,9 +332,10 @@ namespace Microsoft.AspNetCore.Mvc } [Theory] - [InlineData(null, "\"Etag\"")] - [InlineData(null, null)] - public void GetPreconditionState_ShouldNotProcess_NotModified(string ifMatch, string ifNoneMatch) + [InlineData(null, "\"Etag\"", true)] + [InlineData(null, "\"Etag\"", false)] + [InlineData(null, null, false)] + public void GetPreconditionState_ShouldNotProcess_NotModified(string ifMatch, string ifNoneMatch, bool isWeak) { // Arrange var actionContext = new ActionContext(); @@ -347,7 +352,7 @@ namespace Microsoft.AspNetCore.Mvc httpRequestHeaders.IfNoneMatch = ifNoneMatch == null ? null : new[] { - new EntityTagHeaderValue(ifNoneMatch), + new EntityTagHeaderValue(ifNoneMatch, isWeak), }; httpRequestHeaders.IfModifiedSince = lastModified; actionContext.HttpContext = httpContext;