Merge pull request #1388 from tgstation/FixBrowserCaching [TGSDeploy]

Set Cache-Control: no-cache for API responses
This commit is contained in:
Jordan Dominion
2022-09-25 02:29:26 -04:00
committed by GitHub
3 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
<!-- Integration tests will ensure they match across the board -->
<Import Project="ControlPanelVersion.props" />
<PropertyGroup>
<TgsCoreVersion>5.0.1</TgsCoreVersion>
<TgsCoreVersion>5.0.2</TgsCoreVersion>
<TgsConfigVersion>4.2.0</TgsConfigVersion>
<TgsApiVersion>9.6.0</TgsApiVersion>
<TgsApiLibraryVersion>9.6.1</TgsApiLibraryVersion>
@@ -467,6 +467,9 @@ namespace Tgstation.Server.Host.Core
else
logger.LogTrace("Web control panel disabled!");
// Do not cache a single thing beyond this point, it's all API
applicationBuilder.UseDisabledClientCache();
// authenticate JWT tokens using our security pipeline if present, returns 401 if bad
applicationBuilder.UseAuthentication();
@@ -8,6 +8,8 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Models.Response;
@@ -56,6 +58,21 @@ namespace Tgstation.Server.Host.Extensions
});
}
/// <summary>
/// Suppress any client side caching of API calls.
/// </summary>
/// <param name="applicationBuilder">The <see cref="IApplicationBuilder"/> to configure.</param>
public static void UseDisabledClientCache(this IApplicationBuilder applicationBuilder)
{
if (applicationBuilder == null)
throw new ArgumentNullException(nameof(applicationBuilder));
applicationBuilder.Use(async (context, next) =>
{
context.Response.Headers.Add(HeaderNames.CacheControl, new StringValues("no-cache"));
await next();
});
}
/// <summary>
/// Suppress <see cref="global::System.Threading.Tasks.TaskCanceledException"/> warnings when a user aborts a request.
/// </summary>