robertwayne / axum-htmx

A set of htmx extractors, responders, and request guards for axum.
Apache License 2.0
186 stars 10 forks source link

Vary headers #14

Closed imbolc closed 6 months ago

imbolc commented 6 months ago

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?

robertwayne commented 6 months ago

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

imbolc commented 6 months ago

Done

imbolc commented 6 months ago

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?

robertwayne commented 6 months ago

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.

imbolc commented 6 months ago

Ok, I've opened a separate issue for this