kornelski / http-cache-semantics

RFC 7234 in JavaScript. Parses HTTP headers to correctly compute cacheability of responses, even in complex cases
http://httpwg.org/specs/rfc7234.html
BSD 2-Clause "Simplified" License
244 stars 27 forks source link

Request cache-control: max-age header is ignored #22

Closed gajus closed 4 years ago

gajus commented 5 years ago

Request headers:

{
  host: '127.0.0.1:3050',
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' +
    'AppleWebKit/537.36 (KHTML, like Gecko) ' +
    'Chrome/75.0.3770.100 Safari/537.36',
  accept: '*/*',
  'accept-encoding': 'gzip',
  'proxy-connection': 'Keep-Alive',
  'cache-control': 'max-age=2'
}
cachePolicy.storable() true
cachePolicy.timeToLive() 3599997

I expect timeToLive to be 2000 regardless of the response headers.

kornelski commented 5 years ago

The max-age in a request header is not an override for max-age. It's a negotiation:

https://tools.ietf.org/html/rfc7234#section-5.2.1

Still, I don't recall if it's implemented. The requirement is a bit weird, so I suspect it's for odd cases like conditional PUT. The more useful max-stale is implemented.