KevinDockx / HttpCacheHeaders

ASP.NET Core middleware that adds HttpCache headers to responses (Cache-Control, Expires, ETag, Last-Modified), and implements cache expiration & validation models
MIT License
271 stars 57 forks source link

updates to support non-mvc http header attributes #135

Closed shawnwildermuth closed 10 months ago

shawnwildermuth commented 10 months ago

This is a real fix to the minimal api support. Evidently the IAsyncResourceFilter isn't supported outside of MVC. So I had to inject the attributes during the request. To support this, I created two interfaces:

Added code to add a request delegate for the endpoint (if it is a IModelOptionsProvider - otherwise we don't need it) and after injecting the data into the HttpContext items, I call the default request delegate. Essentially injecting this code into hte pipeline.

Caveat:

We might able to implement this cleaner with an EndpointFilter but that is only support in .NET 7+. Unless you're building specific versions for .NET 6, 7 and 8 - I didn't feel comfortable adding #if NET7_OR_GREATER into the codebase.

Let me know what you think!

KevinDockx commented 10 months ago

Hi Shawn, this looks good to me! :) I agree on not going for the EndpointFilter approach at this moment. This may be something to consider when .NET 6 goes out of support (I try to follow that release schedule regarding the versions this package should keep supporting) & the compiler directive won't be needed anymore.

KevinDockx commented 10 months ago

FYI, pre-release: https://www.nuget.org/packages/Marvin.Cache.Headers/7.1.0-beta