axum-htmx
                                
                                 axum-htmx copied to clipboard
                                
                                    axum-htmx copied to clipboard
                            
                            
                            
                        Vary header middleware
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
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
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.
Addressed with #21 and the v0.6 release.