diff options
-rw-r--r-- | Timeline.Tests/IntegratedTests/UserAvatarTests.cs | 4 | ||||
-rw-r--r-- | Timeline/Controllers/UserAvatarController.cs | 5 |
2 files changed, 5 insertions, 4 deletions
diff --git a/Timeline.Tests/IntegratedTests/UserAvatarTests.cs b/Timeline.Tests/IntegratedTests/UserAvatarTests.cs index a98d807e..246125d0 100644 --- a/Timeline.Tests/IntegratedTests/UserAvatarTests.cs +++ b/Timeline.Tests/IntegratedTests/UserAvatarTests.cs @@ -70,6 +70,10 @@ namespace Timeline.Tests.IntegratedTests res.Content.Headers.ContentType.MediaType.Should().Be("image/png");
var body = await res.Content.ReadAsByteArrayAsync();
body.Should().Equal(defaultAvatarData);
+ var cacheControl = res.Headers.CacheControl;
+ cacheControl.NoCache.Should().BeTrue();
+ cacheControl.NoStore.Should().BeFalse();
+ cacheControl.MaxAge.Should().NotBeNull().And.Be(TimeSpan.Zero);
eTag = res.Headers.ETag;
}
diff --git a/Timeline/Controllers/UserAvatarController.cs b/Timeline/Controllers/UserAvatarController.cs index 96b43bdb..e7e12d0b 100644 --- a/Timeline/Controllers/UserAvatarController.cs +++ b/Timeline/Controllers/UserAvatarController.cs @@ -61,11 +61,10 @@ namespace Timeline.Controllers [HttpGet("users/{username}/avatar")]
[Authorize]
+ [ResponseCache(NoStore = false, Location = ResponseCacheLocation.None, Duration = 0)]
public async Task<IActionResult> Get([FromRoute] string username)
{
const string IfNonMatchHeaderKey = "If-None-Match";
- const string CacheControlHeaderKey = "Cache-Control";
- const string CacheControlHeaderValue = "no-cache, must-revalidate, max-age=1";
try
{
@@ -79,7 +78,6 @@ namespace Timeline.Controllers if (eTagList.FirstOrDefault(e => e.Equals(eTag)) != null)
{
- Response.Headers.Add(CacheControlHeaderKey, CacheControlHeaderValue);
Response.Headers.Add("ETag", eTagValue);
return StatusCode(StatusCodes.Status304NotModified);
}
@@ -88,7 +86,6 @@ namespace Timeline.Controllers var avatarInfo = await _service.GetAvatar(username);
var avatar = avatarInfo.Avatar;
- Response.Headers.Add(CacheControlHeaderKey, CacheControlHeaderValue);
return File(avatar.Data, avatar.Type, new DateTimeOffset(avatarInfo.LastModified), eTag);
}
catch (UserNotExistException e)
|