Cache should use weak comparison for ETags
This commit is contained in:
parent
aec2a7c2d2
commit
9e5dbee208
|
|
@ -336,7 +336,7 @@ namespace Microsoft.AspNetCore.ResponseCaching
|
||||||
{
|
{
|
||||||
foreach (var tag in ifNoneMatchHeader)
|
foreach (var tag in ifNoneMatchHeader)
|
||||||
{
|
{
|
||||||
if (cachedResponseHeaders.ETag.Compare(tag, useStrongComparison: true))
|
if (cachedResponseHeaders.ETag.Compare(tag, useStrongComparison: false))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -196,16 +196,31 @@ namespace Microsoft.AspNetCore.ResponseCaching.Tests
|
||||||
Assert.False(ResponseCacheMiddleware.ConditionalRequestSatisfied(context));
|
Assert.False(ResponseCacheMiddleware.ConditionalRequestSatisfied(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
public static TheoryData<EntityTagHeaderValue, EntityTagHeaderValue> EquivalentWeakETags
|
||||||
public void ConditionalRequestSatisfied_IfNoneMatch_ExplicitWithMatch_Passes()
|
{
|
||||||
|
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();
|
var context = TestUtils.CreateTestContext();
|
||||||
context.CachedResponseHeaders = new ResponseHeaders(new HeaderDictionary())
|
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));
|
Assert.True(ResponseCacheMiddleware.ConditionalRequestSatisfied(context));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue