pquerna / cachecontrol

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

Can't parse correctly Cache-Control value without spaces #3

Closed slotix closed 7 years ago

slotix commented 7 years ago

If no-cache,no-store,max-age=0,must-revalidate is received by func parse(value string, cd cacheDirective) error as a value it reports the following error strconv.ParseUint: parsing "0,must-revalidate": invalid syntax

pquerna commented 7 years ago

Hmm, kinda a tricky one actually.

A couple of the keys have 'field values', eg, private: https://tools.ietf.org/html/rfc7234#section-5.2.2.6

So an example of where splitting the token after the first ,, which would break is this:

private=Set-Cookie,Request-Id public

Going off the RFC into the real world, I guess there are "simple" field values, eg, mostly integers, and the there are un-quoted, complex field values, in which splitting by a comma is not a good thing. I'm thinking a whitelist of these keytypes with #field-name values which are: no-store, private

slotix commented 7 years ago

Actually I've tested the code with http://yandex.com as an example. It works ok with the last commit. Thank you

pquerna commented 7 years ago

Yeah, the PR "fixes" this case, but breaks parsing for the other... so I think i need a bigger change to make it support both

slotix commented 7 years ago

I don't care about this particular website and will stay with master brunch. As a quick fix I can add spaces by hands after each comma before sending to parser. So the string will look like no-cache, no-store, max-age=0, must-revalidate What do you think? I just care about not breaking other things.