pquerna / cachecontrol

Golang HTTP Cache-Control Parser and Interpretation
Apache License 2.0
133 stars 17 forks source link

Support for Vary header #25

Open bofia opened 2 years ago

bofia commented 2 years ago

The Vary header can change the cacheability of a response. This library could add some helpers to account for it. A dev would probably want to create a cache key based on the headers in Vary

Proposal:

  1. Add additional return value to CachableResponse of []string that is the list of headers in the Vary header. E.g. ["Accept-Language", "Accept-Encoding"]
  2. Add helper to extract headers from a http.Request based on the Vary list
  3. Add normalization helpers for certain headers. See https://developer.fastly.com/reference/http/http-headers/Accept-Language/
pquerna commented 2 years ago

This would be a great pull request, and I like how the proposal is split into 3 separate isolated changes.

I assume for #1 you would use the normalization function right? Just thinking out loud - Does it make sense to have a "type" for the normalized vary header to avoid extra parsing in #2? String might be fine enough.

Is there a 4th function here, a "cache keys" function, that could return a map[string]string of cache keys or a similar interface? (i think actually hashing the keys should be done outside of this library - many different ways people might want to do that)