Skip to content

Commit 25d3fc9

Browse files
Change Cache-Control header when cache buster value is present
1 parent d222972 commit 25d3fc9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilder.ImageSharp.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System.Collections.Generic;
22
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.Http;
34
using Microsoft.Extensions.Configuration;
45
using Microsoft.Extensions.DependencyInjection;
56
using Microsoft.Extensions.Options;
7+
using Microsoft.Net.Http.Headers;
68
using SixLabors.ImageSharp.Web.Caching;
79
using SixLabors.ImageSharp.Web.Commands;
810
using SixLabors.ImageSharp.Web.DependencyInjection;
@@ -48,6 +50,24 @@ public static IServiceCollection AddUmbracoImageSharp(this IUmbracoBuilder build
4850
context.Commands.Remove(ResizeWebProcessor.Height);
4951
}
5052

53+
return Task.CompletedTask;
54+
};
55+
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
56+
options.OnProcessedAsync = _ => Task.CompletedTask;
57+
options.OnPrepareResponseAsync = context =>
58+
{
59+
// Change Cache-Control header when cache buster value is present
60+
if (context.Request.Query.ContainsKey("rnd"))
61+
{
62+
var headers = context.Response.GetTypedHeaders();
63+
64+
var cacheControl = headers.CacheControl;
65+
cacheControl.MustRevalidate = false;
66+
cacheControl.Extensions.Add(new NameValueHeaderValue("immutable"));
67+
68+
headers.CacheControl = cacheControl;
69+
}
70+
5171
return Task.CompletedTask;
5272
};
5373
})

0 commit comments

Comments
 (0)