[backend/asp] Add Vary: Accept to routes with MediaTypeRouteFilterAttribute
This commit is contained in:
parent
a20d50f793
commit
a70b493188
1 changed files with 4 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
using System.Net.Http.Headers;
|
||||
using Microsoft.AspNetCore.Mvc.ActionConstraints;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Iceshrimp.Backend.Controllers.Attributes;
|
||||
|
||||
|
@ -8,6 +9,9 @@ public class MediaTypeRouteFilterAttribute(params string[] mediaTypes) : Attribu
|
|||
{
|
||||
public bool Accept(ActionConstraintContext context)
|
||||
{
|
||||
// Add Vary: Accept to the response headers to prevent caches serving the wrong response
|
||||
context.RouteContext.HttpContext.Response.Headers.Append(HeaderNames.Vary, HeaderNames.Accept);
|
||||
|
||||
if (!context.RouteContext.HttpContext.Request.Headers.ContainsKey("Accept")) return false;
|
||||
|
||||
var accept = context.RouteContext.HttpContext.Request.Headers.Accept.ToString()
|
||||
|
|
Loading…
Add table
Reference in a new issue