From 18b7bcb9e3698cf62bc6fe50a02eb9f2cb50a6f2 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 18 Jun 2018 13:35:46 -0400 Subject: [PATCH] no response cache. manual CacheControl middleware --- src/Icons/Controllers/IconsController.cs | 1 - src/Icons/Startup.cs | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Icons/Controllers/IconsController.cs b/src/Icons/Controllers/IconsController.cs index b15e947de3..1f6d918003 100644 --- a/src/Icons/Controllers/IconsController.cs +++ b/src/Icons/Controllers/IconsController.cs @@ -28,7 +28,6 @@ namespace Bit.Icons.Controllers } [HttpGet("{hostname}/icon.png")] - [ResponseCache(Duration = 604800 /*7 days*/)] public async Task Get(string hostname) { if(string.IsNullOrWhiteSpace(hostname) || !hostname.Contains(".")) diff --git a/src/Icons/Startup.cs b/src/Icons/Startup.cs index 0573a44f23..9310bbfe6a 100644 --- a/src/Icons/Startup.cs +++ b/src/Icons/Startup.cs @@ -2,8 +2,10 @@ using Bit.Icons.Services; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Net.Http.Headers; namespace Bit.Icons { @@ -31,7 +33,6 @@ namespace Bit.Icons { options.SizeLimit = iconsSettings.CacheSizeLimit; }); - services.AddResponseCaching(); // Services services.AddSingleton(); @@ -50,7 +51,16 @@ namespace Bit.Icons app.UseDeveloperExceptionPage(); } - app.UseResponseCaching(); + app.Use(async (context, next) => + { + context.Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue + { + Public = true, + MaxAge = TimeSpan.FromDays(7) + }; + await next(); + }); + app.UseMvc(); } }