robertwayne / axum-htmx

A set of htmx extractors, responders, and request guards for axum.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vary headers

imbolc opened this issue · comments

Differentiating response based on hx-request / hx-trigger involves a caching issue. A way of dealing with it is corresponding Vary response headers. Maybe we add vary responders e.g. VaryHxRequest and convenience methods on extractors HxRequest::vary_header() -> VaryHxRequest?

commented

I agree, this would make sense to add. That API seems fine. Would you like to open a PR for this?

Done

The same Vary header value should be used on all responses for a given URL, including 304 Not Modified responses and the "default" response. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary

Shouldn't we also (or instead) add a layer (middleware) to add a single Vary: hx-request, hx-target, hx-trigger, hx-trigger-name header to every response?

commented

I've been thinking about this for a bit, and I can't come up with any issues off the top of my head. Are there any potentially problematic implications of applying this header to every response going through the middleware?

Either way, if we do add a middleware, it should live alongside the individual options for flexibility's sake.

Ok, I've opened a separate issue for this