Skip to content
This repository was archived by the owner on Nov 22, 2018. It is now read-only.

Commit 9e5dbee

Browse files
committed
Cache should use weak comparison for ETags
1 parent aec2a7c commit 9e5dbee

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/Microsoft.AspNetCore.ResponseCaching/ResponseCacheMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ internal static bool ConditionalRequestSatisfied(ResponseCacheContext context)
336336
{
337337
foreach (var tag in ifNoneMatchHeader)
338338
{
339-
if (cachedResponseHeaders.ETag.Compare(tag, useStrongComparison: true))
339+
if (cachedResponseHeaders.ETag.Compare(tag, useStrongComparison: false))
340340
{
341341
return true;
342342
}

test/Microsoft.AspNetCore.ResponseCaching.Tests/ResponseCacheMiddlewareTests.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,31 @@ public void ConditionalRequestSatisfied_IfNoneMatch_AnyWithoutETagInResponse_Pas
196196
Assert.False(ResponseCacheMiddleware.ConditionalRequestSatisfied(context));
197197
}
198198

199-
[Fact]
200-
public void ConditionalRequestSatisfied_IfNoneMatch_ExplicitWithMatch_Passes()
199+
public static TheoryData<EntityTagHeaderValue, EntityTagHeaderValue> EquivalentWeakETags
200+
{
201+
get
202+
{
203+
return new TheoryData<EntityTagHeaderValue, EntityTagHeaderValue>
204+
{
205+
{ new EntityTagHeaderValue("\"tag\""), new EntityTagHeaderValue("\"tag\"") },
206+
{ new EntityTagHeaderValue("\"tag\"", true), new EntityTagHeaderValue("\"tag\"") },
207+
{ new EntityTagHeaderValue("\"tag\""), new EntityTagHeaderValue("\"tag\"", true) },
208+
{ new EntityTagHeaderValue("\"tag\"", true), new EntityTagHeaderValue("\"tag\"", true) }
209+
};
210+
}
211+
}
212+
213+
[Theory]
214+
[MemberData(nameof(EquivalentWeakETags))]
215+
public void ConditionalRequestSatisfied_IfNoneMatch_ExplicitWithMatch_Passes(EntityTagHeaderValue responseETag, EntityTagHeaderValue requestETag)
201216
{
202217
var context = TestUtils.CreateTestContext();
203218
context.CachedResponseHeaders = new ResponseHeaders(new HeaderDictionary())
204219
{
205-
ETag = new EntityTagHeaderValue("\"E1\"")
220+
ETag = responseETag
206221
};
207222

208-
context.TypedRequestHeaders.IfNoneMatch = new List<EntityTagHeaderValue>(new[] { new EntityTagHeaderValue("\"E1\"") });
223+
context.TypedRequestHeaders.IfNoneMatch = new List<EntityTagHeaderValue>(new[] { requestETag });
209224

210225
Assert.True(ResponseCacheMiddleware.ConditionalRequestSatisfied(context));
211226
}

0 commit comments

Comments
 (0)