http-extensions icon indicating copy to clipboard operation
http-extensions copied to clipboard

Cookies

Open mnot opened this issue 7 years ago • 6 comments

Would an algorithm to key the cache on a cookie by name work?

(moved from mnot/I-D)

mnot avatar Apr 02 '18 02:04 mnot

I think the basic use case here is "a request with a cookie named X whose value matches Y can use this response," where X is nominated in the Variants header, and Y is matched in the request (and Variant-Key).

E.g.,

Variants: cookie; foo
Variant-Key: 1

Could be used to match a request with:

Cookie: foo=1

TBD:

  • [ ] Is that enough? Other use cases?
  • [ ] See how the actual algorithm / serialisation works
  • [ ] Handle cases where the cookie isn't present
  • [ ] How does it work with multiple cookies? Combining with other headers?

mnot avatar Nov 13 '18 05:11 mnot

That looks like a different meaning for Variants than the spec defines. Specifically, the ABNFs are:

Variants        = 1#variant-item
variant-item    = field-name *( OWS ";" OWS available-value )
available-value = ...
Variant-Key      = 1#available-values
available-values = available-value *( ";" available-value )

Your suggestion for cookies has Variants formatted like field-name *(";" subfield-name) instead. That'll lead to the result of https://httpwg.org/http-extensions/draft-ietf-httpbis-variants.html#cache never matching the normalized Variant-Keys value, and the cache will never return one of these responses.

If you want to select particular cookies, I think you need to mess with the field-name part of the Variants header, perhaps by delimiting subfields by a non-tchar.

jyasskin avatar Dec 13 '18 21:12 jyasskin

Yes, that was from a previous syntax - thanks for the reminder.

mnot avatar Feb 06 '19 07:02 mnot

See proposal roughed in above; @jyasskin I'm curious to know if this seems sensible to you.

mnot avatar Aug 30 '19 10:08 mnot

The current text for cookies does not work with structured headers, more specifically this part:

Note that if more than one cookie-name serves as a cache key,
they’ll need to be listed in separate Variants members, like this:

Variants: Cookie=(user_priority), Cookie=(user_region)
Variant-Key: (gold europe)
Vary: Cookie

The problem is that in https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-14#section-3.2 it says:

There can be zero or more members, and their names are required to be
unique within the scope of the dictionary they occur within.

So unless I'm mistaken we cannot have cookie twice. And you can't really put the cookie name as the member name due to syntax restrictions (lowercase plus a small set of allowed characters). Maybe a special variant header for cookies would work better?

essen avatar Nov 25 '19 09:11 essen

This one is probably wrong as well because 0 is not a string or token, it's an integer. It probably should be "0".

   Variants: Cookie=(logged_in)
   Variant-Key: (0)
   Vary: Cookie

essen avatar Nov 25 '19 11:11 essen