axum-htmx icon indicating copy to clipboard operation
axum-htmx copied to clipboard

Vary header middleware

Open imbolc opened this issue 1 year ago • 2 comments

As discussed in #14 we could have a middleware to add a single Vary: hx-request, hx-target, hx-trigger, hx-trigger-name header to every response to address all possible HTMx caching issues.

This addresses the major issue of separate Vary responders approach - the need to manually ensure they're properly applied, which means that it's just a matter of time before they aren't ;)

I've asked what people think of this approach:

Let's give them some time to react before implementing this

imbolc avatar May 08 '24 04:05 imbolc

We can make the middleware more selective, so it would add Vary headers only when corresponding extractors are used. For it would add Vary: HX-Request only if HxRequest extractor has been used.

On implementation:

the way i would do it is add a oneshot sender into the extensions, wrapped in your own type, and then send to it when the extractor is used- and read out of it when you go to add the header later in the middleware you could also definitely use atomics for this, but you'd have to be careful with your orderings https://discord.com/channels/500028886025895936/870760546109116496/threads/1238703182679642142

imbolc avatar May 11 '24 05:05 imbolc

I've been thinking about this. I'm primarily concerned with complexity, so I definitely want to be thoughtful about the implementation. A oneshot channel certainly seems like it might be the best way to start approaching this, barring any other ideas you may have come up with.

robertwayne avatar May 13 '24 22:05 robertwayne

Addressed with #21 and the v0.6 release.

robertwayne avatar Jun 24 '24 22:06 robertwayne