File tree Expand file tree Collapse file tree
tests/StatusPageSharp.Web.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99 <Folder Name =" /tests/" >
1010 <Project Path =" tests/StatusPageSharp.Domain.Tests/StatusPageSharp.Domain.Tests.csproj" />
1111 <Project Path =" tests/StatusPageSharp.Infrastructure.Tests/StatusPageSharp.Infrastructure.Tests.csproj" />
12+ <Project Path =" tests/StatusPageSharp.Web.Tests/StatusPageSharp.Web.Tests.csproj" />
1213 </Folder >
1314</Solution >
Original file line number Diff line number Diff line change 1+ using Microsoft . AspNetCore . Http ;
2+ using Microsoft . Net . Http . Headers ;
3+
4+ namespace StatusPageSharp . Web . Caching ;
5+
6+ public static class StatusCardResponseCacheHeaders
7+ {
8+ private const string CdnCacheControlHeaderName = "CDN-Cache-Control" ;
9+ private const string CloudflareCdnCacheControlHeaderName = "Cloudflare-CDN-Cache-Control" ;
10+ private const string NoStoreDirective = "no-store" ;
11+
12+ public static void Apply ( IHeaderDictionary headers )
13+ {
14+ headers [ HeaderNames . CacheControl ] = NoStoreDirective ;
15+ headers [ CdnCacheControlHeaderName ] = NoStoreDirective ;
16+ headers [ CloudflareCdnCacheControlHeaderName ] = NoStoreDirective ;
17+ }
18+ }
Original file line number Diff line number Diff line change 11using StatusPageSharp . Application . Abstractions ;
2+ using StatusPageSharp . Web . Caching ;
23using StatusPageSharp . Web . Rendering ;
34
45namespace StatusPageSharp . Web . Extensions ;
@@ -59,15 +60,19 @@ CancellationToken cancellationToken
5960 . MapGet (
6061 "/status-card.png" ,
6162 async (
63+ HttpContext httpContext ,
6264 IPublicStatusService publicStatusService ,
6365 CancellationToken cancellationToken
6466 ) =>
65- TypedResults . File (
67+ {
68+ StatusCardResponseCacheHeaders . Apply ( httpContext . Response . Headers ) ;
69+ return TypedResults . File (
6670 SocialStatusCardRenderer . Render (
6771 await publicStatusService . GetSiteSummaryAsync ( cancellationToken )
6872 ) ,
6973 "image/png"
70- )
74+ ) ;
75+ }
7176 )
7277 . CacheOutput ( "StatusCard" ) ;
7378
Original file line number Diff line number Diff line change 1+ using Microsoft . AspNetCore . Http ;
2+ using Microsoft . Net . Http . Headers ;
3+ using StatusPageSharp . Web . Caching ;
4+
5+ namespace StatusPageSharp . Web . Tests . Caching ;
6+
7+ public class StatusCardResponseCacheHeadersTests
8+ {
9+ [ Fact ]
10+ public void Apply_SetsNoStoreHeaders_ForBrowsersAndCdns ( )
11+ {
12+ var headers = new HeaderDictionary ( ) ;
13+
14+ StatusCardResponseCacheHeaders . Apply ( headers ) ;
15+
16+ Assert . Equal ( "no-store" , headers [ HeaderNames . CacheControl ] . ToString ( ) ) ;
17+ Assert . Equal ( "no-store" , headers [ "CDN-Cache-Control" ] . ToString ( ) ) ;
18+ Assert . Equal ( "no-store" , headers [ "Cloudflare-CDN-Cache-Control" ] . ToString ( ) ) ;
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ <Project Sdk =" Microsoft.NET.Sdk" >
2+ <PropertyGroup >
3+ <TargetFramework >net10.0</TargetFramework >
4+ <LangVersion >14.0</LangVersion >
5+ <ImplicitUsings >enable</ImplicitUsings >
6+ <Nullable >enable</Nullable >
7+ <IsPackable >false</IsPackable >
8+ </PropertyGroup >
9+
10+ <ItemGroup >
11+ <PackageReference Include =" coverlet.collector" />
12+ <PackageReference Include =" Microsoft.NET.Test.Sdk" />
13+ <PackageReference Include =" xunit" />
14+ <PackageReference Include =" xunit.runner.visualstudio" />
15+ </ItemGroup >
16+
17+ <ItemGroup >
18+ <Using Include =" Xunit" />
19+ </ItemGroup >
20+
21+ <ItemGroup >
22+ <ProjectReference Include =" ..\..\src\StatusPageSharp.Web\StatusPageSharp.Web.csproj" />
23+ </ItemGroup >
24+ </Project >
You can’t perform that action at this time.
0 commit comments