Class VaryAcceptMiddleware
- Namespace
- Cuemon.AspNetCore.Http.Headers
- Assembly
- Cuemon.AspNetCore.dll
Middleware that appends Vary: Accept to every response, signalling to HTTP
caches (and clients) that the representation varies based on the Accept
request header (RFC 9110 ยง12.5.5).
public class VaryAcceptMiddleware : Middleware
- Inheritance
-
VaryAcceptMiddleware
- Inherited Members
Constructors
VaryAcceptMiddleware(RequestDelegate)
Initializes a new instance of the VaryAcceptMiddleware class.
public VaryAcceptMiddleware(RequestDelegate next)
Parameters
nextRequestDelegateThe next RequestDelegate in the ASP.NET Core request processing pipeline. This delegate is invoked after this middleware has performed its work.
Methods
InvokeAsync(HttpContext)
Invokes the middleware for the given HttpContext.
Adds the Vary: Accept response header just before the response starts.
public override Task InvokeAsync(HttpContext context)
Parameters
contextHttpContextThe current HttpContext.
Returns
- Task
A Task that represents the asynchronous operation of this middleware. The returned task completes when the remaining pipeline has finished processing.
Remarks
The header is appended using OnStarting(Func<Task>)
to ensure the header is present even if the response body is being streamed or the response
was started by downstream middleware. This signals to intermediaries and clients that the
response representation depends on the request's Accept header.