Cache should use weak comparison for ETags

This commit is contained in:
John Luo 2016-10-04 16:03:25 -07:00
parent aec2a7c2d2
commit 9e5dbee208
2 changed files with 20 additions and 5 deletions

View File

@ -336,7 +336,7 @@ namespace Microsoft.AspNetCore.ResponseCaching
{
foreach (var tag in ifNoneMatchHeader)
{
if (cachedResponseHeaders.ETag.Compare(tag, useStrongComparison: true))
if (cachedResponseHeaders.ETag.Compare(tag, useStrongComparison: false))
{
return true;
}

View File

@ -196,16 +196,31 @@ namespace Microsoft.AspNetCore.ResponseCaching.Tests
Assert.False(ResponseCacheMiddleware.ConditionalRequestSatisfied(context));
}
[Fact]
public void ConditionalRequestSatisfied_IfNoneMatch_ExplicitWithMatch_Passes()
public static TheoryData<EntityTagHeaderValue, EntityTagHeaderValue> EquivalentWeakETags
{
get
{
return new TheoryData<EntityTagHeaderValue, EntityTagHeaderValue>
{
{ new EntityTagHeaderValue("\"tag\""), new EntityTagHeaderValue("\"tag\"") },
{ new EntityTagHeaderValue("\"tag\"", true), new EntityTagHeaderValue("\"tag\"") },
{ new EntityTagHeaderValue("\"tag\""), new EntityTagHeaderValue("\"tag\"", true) },
{ new EntityTagHeaderValue("\"tag\"", true), new EntityTagHeaderValue("\"tag\"", true) }
};
}
}
[Theory]
[MemberData(nameof(EquivalentWeakETags))]
public void ConditionalRequestSatisfied_IfNoneMatch_ExplicitWithMatch_Passes(EntityTagHeaderValue responseETag, EntityTagHeaderValue requestETag)
{
var context = TestUtils.CreateTestContext();
context.CachedResponseHeaders = new ResponseHeaders(new HeaderDictionary())
{
ETag = new EntityTagHeaderValue("\"E1\"")
ETag = responseETag
};
context.TypedRequestHeaders.IfNoneMatch = new List<EntityTagHeaderValue>(new[] { new EntityTagHeaderValue("\"E1\"") });
context.TypedRequestHeaders.IfNoneMatch = new List<EntityTagHeaderValue>(new[] { requestETag });
Assert.True(ResponseCacheMiddleware.ConditionalRequestSatisfied(context));
}